ssh2 action中通过ActionContext取得HttpServletRequest对象 然后使request.getParameter("参数名")得到参数值
来源:互联网 发布:社交软件推荐 编辑:程序博客网 时间:2024/06/05 18:53
http://zhougaoyun.iteye.com/blog/1979047 从这个地址拷贝来备自己以后查用
struts2在action获取表单请求的方式与jquery get参数方式
1、jquery中要在get中传递参数
$(function(){
$.get(url,{username:user,password:pass},function(data){
window.location.href="main.jsp";
});
});
2、表单
1)当把参数作为Action的类属性,且提供属性的getter/setter方法时,xwork的OGNL会自动把request参数的值设置到类属性中,此时访问请求参数只需要访问类属性即可。
System.out.println("方法一,把参数作为Action的类属性,让OGNL自动填充:");
System.out.println("bookName: "+this.bookName);
System.out.println("bookPrice: " +this.bookPrice);
2)[color=darkred]可以通过ActionContext对象Map parameterMap=context.getParameters();方法,得到请求参数Map,然后通过parameterMap来获取请求参数。需要注意的是:当通过parameterMap的键取得参数值时,取得是一个数组对象,即同名参数的值的集合 。[/color]
ActionContext context=ActionContext.getContext();
Map parameterMap=context.getParameters();
String bookName2[]=(String[])parameterMap.get("bookName");
String bookPrice2[]=(String[])parameterMap.get("bookPrice");
System.out.println("方法二,在Action中使用ActionContext得到parameterMap获取参数:");
System.out.println("bookName: " +bookName2[0]);
System.out.println("bookPrice: " +bookPrice2[0]);
3)通过ActionContext取得HttpServletRequest对象,然后使request.getParameter("参数名")得到参数值。
HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
String bookName=request.getParameter("bookName");
String bookPrice=request.getParameter("bookPrice");
System.out.println("方法三,在Action中取得HttpServletRequest对象,使用request.getParameter获取参数:");
System.out.println("bookName: " +bookName);
System.out.println("bookPrice: " +bookPrice);
$(function(){
$.get(url,{username:user,password:pass},function(data){
window.location.href="main.jsp";
});
});
2、表单
1)当把参数作为Action的类属性,且提供属性的getter/setter方法时,xwork的OGNL会自动把request参数的值设置到类属性中,此时访问请求参数只需要访问类属性即可。
System.out.println("方法一,把参数作为Action的类属性,让OGNL自动填充:");
System.out.println("bookName: "+this.bookName);
System.out.println("bookPrice: " +this.bookPrice);
2)[color=darkred]可以通过ActionContext对象Map parameterMap=context.getParameters();方法,得到请求参数Map,然后通过parameterMap来获取请求参数。需要注意的是:当通过parameterMap的键取得参数值时,取得是一个数组对象,即同名参数的值的集合 。[/color]
ActionContext context=ActionContext.getContext();
Map parameterMap=context.getParameters();
String bookName2[]=(String[])parameterMap.get("bookName");
String bookPrice2[]=(String[])parameterMap.get("bookPrice");
System.out.println("方法二,在Action中使用ActionContext得到parameterMap获取参数:");
System.out.println("bookName: " +bookName2[0]);
System.out.println("bookPrice: " +bookPrice2[0]);
3)通过ActionContext取得HttpServletRequest对象,然后使request.getParameter("参数名")得到参数值。
HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
String bookName=request.getParameter("bookName");
String bookPrice=request.getParameter("bookPrice");
System.out.println("方法三,在Action中取得HttpServletRequest对象,使用request.getParameter获取参数:");
System.out.println("bookName: " +bookName);
System.out.println("bookPrice: " +bookPrice);
0 0
- ssh2 action中通过ActionContext取得HttpServletRequest对象 然后使request.getParameter("参数名")得到参数值
- forward是否共享一个request,能否通过getParameter取得参数
- 在HttpServletRequest request获得参数,通过类的set方法封装到对象中
- request.getParameter(“参数名”) 中文乱码解决方法
- request.getParameter(“参数名”) 中文乱码解决方法
- request.getParameter(“参数名”) 中文乱码解决方法
- request.getParameter(“参数名”) 中文乱码解决方法
- request.getParameter(“参数名”) 中文乱码解决方法
- request.getParameter(“参数名”) 中文乱码解决方法
- request.getParameter(“参数名”) 中文乱码解决方法
- Action中获取HttpServletRequest对象的方法(表单提交值,url传递参数)
- 关于struts1.x中Action使用request.getParameter(param)取不到url的参数问题
- Java取得request对象中所有的参数值并生成实体对象工具类
- 取得request对象中所有的参数值并生成一个相应的对象返回
- 在webwork的action里取request.getParameter参数
- struts2 action里取url里的request.getParameter参数
- 在webwork的action里取request.getParameter参数
- 通过action 使用 request.getParameter
- 树状数组之区间求最值
- Ubuntu12.04 NFS服务器安装
- Java经典代码
- Android支付接入:支付宝
- 架构高可用mongodb 集群文档
- ssh2 action中通过ActionContext取得HttpServletRequest对象 然后使request.getParameter("参数名")得到参数值
- Android网络优化之HttpClient
- Linux调用backtrack函数打印程序崩溃时的调用堆栈
- 关于Cannot send session cache limiter - headers already sent错误解决方法
- 拓扑图软件技术对比
- 秋季脸部美白得小窍门,水润肌底白净肤色
- codeforces Round #258(div2) D解题报告
- ie和firefox中通用的设置div最小高度和达到这一最小高度后自适应的css代码
- Office导出导入报错问题