struts之Action中获取request、response对象的方法
来源:互联网 发布:梦入神机 知乎 编辑:程序博客网 时间:2024/05/01 12:45
struts之Action中获取request、response对象的方法
1、访问或添加request/session/application属性
public String scope() throws Exception{
ActionContext ctx = ActionContext.getContext();
ctx.getApplication().put("app", "应用范围");//往ServletContext里放入app
ctx.getSession().put("ses", "session范围");//往session里放入ses
ctx.put("req", "request范围");//往request里放入req
return "scope";
}
JSP:
<body>
${applicationScope.app} <br>
${sessionScope.ses}<br>
${requestScope.req}<br>
</body>
2、获取HttpServletRequest/HttpSession/ServletContext/HttpServletResponse对象
方法一、通过ServletActionContext类直接获取:
public String rsa() throws Exception{
HttpServletRequest request = ServletActionContext.getRequest();
ServletContext servletContext = ServletActionContext.getServletContext();
request.getSession();
HttpServletResponse response = ServletActionContext.getResponse();
return "scope";
}
方法二、实现指定接口,由struts框架运行时注入:
public class HelloWorldAction implements ServletRequestAware, ServletResponseAware, ServletContextAware{
private HttpServletRequest request;
private ServletContext servletContext;
private HttpServletResponse response;
public void setServletRequest(HttpServletRequest req) {
this.request=req;
}
public void setServletResponse(HttpServletResponse res) {
this.response=res;
}
public void setServletContext(ServletContext ser) {
this.servletContext=ser;
}
}
代码
- struts之Action中获取request、response对象的方法
- struts之Action中获取request、response对象的方法
- struts之Action中获取request、response对象的方法
- struts之Action中获取request、response对象的方法
- struts之Action中获取request、response对象的方法
- struts之Action中获取request、response对象的方法
- struts之Action中获取request、response对象的方法
- struts之Action中获取request、response对象的方法
- struts之Action中获取request、response对象的方法
- Struts的Action中获取Request和response对象
- struts2 Action中获取request, response对象的方法
- webwork Action中获取request, response,session对象的方法
- Action中获取request, response对象的方法
- struts2 Action中获取request, response对象的方法
- webwork Action中获取request, response,session对象的方法
- struts2 Action中获取request, response对象的方法
- struts2 Action中获取request, response,Session对象的方法
- struts获取request和response对象的方法
- 正则表达式学习与总结
- Hibernate缓存机制
- 二叉树遍历的各种算法
- <学习笔记>jsp页面画表格固定列数的方法
- 基于C#开发 Windows Embedded Compact 7 应用
- struts之Action中获取request、response对象的方法
- java 构造函数问题
- gdb提供的功能
- HashMap put(K key, V value)解析
- Wikioi 骑士游历
- VS2008部署问题
- 高通公司AllJoyn推动全球物联网发展--关于AllJoyn
- 基于C#开发 Windows Embedded Compact 7 应用 (下)
- VS2008编译的程序在某些机器上运行提示“由于应用程序配置不正确,应用程序未能启动”的问题