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;
}
}
最近下载更多
15828038591 LV11
2025年12月20日
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日
最近浏览更多
15828038591 LV11
2025年12月20日
Sleachp LV8
2023年5月5日
t19611321 LV10
2023年2月12日
阿布屋脊 LV7
2022年5月7日
huaua7676 LV30
2021年9月2日
xiaobaitud LV13
2021年7月5日
sl0018 LV13
2021年7月4日
13561143836 LV7
2021年6月20日
zkx247 LV2
2021年6月18日
小白jmhuang LV12
2021年4月13日

