package com.simpleton.demo.action;
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 result;
public void setServletRequest(HttpServletRequest arg0) {
this.request = arg0;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
/**
* 处理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类型数据
result = json.toString();//给result赋值,传递给页面
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SimpletonDemo.rar (37个子文件)
SimpletonDemo
WebContent
images
Icon.png 24KB
bg.gif 65B
autograph.gif 2KB
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 1KB
lib
ezmorph-1.0.6.jar 84KB
commons-collections-3.2.1.jar 562KB
javassist-3.11.0.GA.jar 600KB
commons-io-1.1.jar 60KB
commons-logging-1.1.1.jar 59KB
commons-beanutils-1.8.0.jar 226KB
servlet-api.jar 86KB
freemarker-2.3.16.jar 860KB
struts2-core-2.2.1.1.jar 755KB
commons-fileupload-1.1.1.jar 31KB
ognl-3.0.jar 224KB
xwork-core-2.2.1.1.jar 997KB
commons-lang-2.5.jar 270KB
struts2-json-plugin-2.1.8.1.jar 50KB
json-lib-2.4-jdk15.jar 155KB
index.html 546B
json_demo.jsp 3KB
sorry.html 548B
styles
base.css 1KB
scripts
jquery-1.8.2.js 261KB
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 305B
org.eclipse.wst.common.component 491B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 503B
org.eclipse.jdt.core.prefs 364B
src
com
simpleton
demo
action
JsonAction.java 1KB
struts.xml 777B
.project 1KB
.classpath 2KB
build
classes
com
simpleton
demo
action
JsonAction.class 2KB
struts.xml 777B
共 37 条
- 1
只是过路人
- 粉丝: 5
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页