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.zip (37个子文件)
SimpletonDemo
.project 1KB
WebContent
WEB-INF
lib
servlet-api.jar 86KB
commons-fileupload-1.1.1.jar 31KB
commons-io-1.1.jar 60KB
ezmorph-1.0.6.jar 84KB
xwork-core-2.2.1.1.jar 997KB
commons-beanutils-1.8.0.jar 226KB
commons-logging-1.1.1.jar 59KB
javassist-3.11.0.GA.jar 600KB
struts2-core-2.2.1.1.jar 755KB
json-lib-2.4-jdk15.jar 155KB
freemarker-2.3.16.jar 860KB
ognl-3.0.jar 224KB
commons-lang-2.5.jar 270KB
commons-collections-3.2.1.jar 562KB
struts2-json-plugin-2.1.8.1.jar 50KB
web.xml 1KB
index.html 546B
sorry.html 548B
styles
base.css 1KB
images
Icon.png 24KB
bg.gif 65B
autograph.gif 2KB
scripts
jquery-1.8.2.js 261KB
META-INF
MANIFEST.MF 39B
json_demo.jsp 3KB
src
struts.xml 777B
com
simpleton
demo
action
JsonAction.java 1KB
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 305B
org.eclipse.jdt.core.prefs 364B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 491B
.jsdtscope 503B
build
classes
struts.xml 777B
com
simpleton
demo
action
JsonAction.class 2KB
.classpath 2KB
共 37 条
- 1
资源评论
ys_yinqin
- 粉丝: 2
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- STM32-Lib-LIS3DSH-Accelerometer-main
- 软件测试面试题.pdf
- WINSOFT ComPort 6.0 for Delphi XE10.1-XE10.3 Cracked
- 数据库基础知识参考试题.doc
- 数据库存储引擎技术的优劣势分析.docx
- 基于GPT的AI文档分析、阅读和问答工具.txt
- 《机器人控制系统的设计与Matlab仿真 》仿真程序
- AI-免费物品无损放大工具AI在线免费放大图片工具.txt
- C++基于DPLL算法的SAT的蜂窝数独游戏求解程序,程序设计综合课程设计,包括SAT求解器板块、蜂窝数独转化成cnf公式板块
- 微信小程序恐龙快跑小程序源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功