package ewr; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import net.sf.json.JSONObject; import org.apache.struts2.interceptor.ServletRequestAware; import com.opensymphony.xwork2.ActionSupport; public class JsonAction extends ActionSupport implements ServletRequestAware{ private static final long serialVersionUID = 1L; private HttpServletRequest request; private String msg; public void setServletRequest(HttpServletRequest arg0) { this.request = arg0; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } /** * 处理ajax请求 * @return SUCCESS */ public String excuteAjax(){ try { //获取数据 String name = request.getParameter("name"); int age = Integer.parseInt(request.getParameter("age")); String position = request.getParameter("position"); //将数据存储在map里,再转换成json类型数据,也可以自己手动构造json类型数据 Map<String,Object> map = new HashMap<String,Object>(); map.put("name", name); map.put("age",age); map.put("position", position); JSONObject json = JSONObject.fromObject(map);//将map对象转换成json类型数据 msg = json.toString();//给result赋值,传递给页面 } catch (Exception e) { e.printStackTrace(); } return SUCCESS; } }

13561143836 LV7
2021年6月20日
小白jmhuang LV12
2021年4月13日
Dhjnbu LV3
2020年6月23日
zdl638 LV6
2020年4月25日
lin904691080 LV1
2020年3月10日
zzyala LV6
2020年2月27日
CATI11 LV4
2019年12月17日
周大福 LV12
2019年10月10日
1832365711 LV15
2019年9月19日
whywhywhy LV10
2019年8月20日