struts2的获取请求方法
来源:互联网 发布:hyper v 网络设置 编辑:程序博客网 时间:2024/06/04 18:41
Struts2获取request三种方法
struts2里面有三种方法可以获取request,最好使用ServletRequestAware接口通过IOC机制注入Request对象。
在Action中获取request方法一:
在Action中的代码:
Map request =(Map)ActionContext.getContext().get("request");
List<Task> tasks =taskManager.findAll();
request.put("tasks", tasks);
在JSP页面中获取其中的值:
<s:iterator id="task"value="#request.tasks">
</s:iterator>
--------------------------------------------------------------------------------------------
方法二:通过ServletActionContext类来获取,使用struts2经验如果处理get传参是中文,只能使用该方法进行处理乱码问题
Action中代码:
HttpServletRequest request =ServletActionContext.getRequest();
request.setAttribute("username", "zhangsan");
在jsp中获取其中的值
--------------------------------------------------------------------------------------------
方法三:通过ServletRequestAware接口通过IOC机制注入Request对象
Action中的代码:
Action实现ServletRequestAware接口,实现接口中的方法
在jsp页面中获取其中的值
<s:propertyvalue="#request.task.tname"/>
0 0
- struts2的获取请求方法
- struts2拦截器中 如果获取当前请求action 和请求的方法
- struts2获取请求的两种方式
- Struts2 HttpServletRequest获取请求参数的过程
- 获取请求目录的方法
- Struts2获取request的方法
- struts2获取参数的方法
- struts2 获取请求相关对象
- struts2 获取请求相关对象
- Struts2中获取请求参数
- Struts2 获取表单请求参数
- struts2中获取请求参数
- struts2 json请求的校验失败获取返回信息
- 【问题】struts2中Action的请求参数获取
- nodejs express 获取请求信息的方法
- jQuery获取URL请求参数的方法
- Post请求鉴权中获取头部的方法
- beego获取用户请求参数的方法
- [C++11 并发编程] 17 超时等待 - time_point
- Win 7 下安装Ubuntu 14.04(完整版)
- Java CheckException与UncheckException
- 按钮测试点
- 【Spring】Spring MVC 的json问题(406 Not Acceptable)
- struts2的获取请求方法
- SSH登陆
- 真机调试的时候出现no identity foundCommand /usr/bin/codesign failed with exit code 1
- 关于list对象的转化问题
- thinkphp url大小写更改
- MongoDB基本使用
- mybatis关于一对一映射返回结果与数据库查出的不符问题
- MySQL索引类型一览 让MySQL高效运行起来
- junit运行多个测试类