码迷,mamicode.com
首页 > 编程语言 > 详细

Struts2,springMVC获取request和response

时间:2016-06-13 15:32:54      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

springMVC获取request和response
1:在BaseController中加入:
   protected HttpServletRequest request;  
   protected HttpServletResponse response;  
   protected HttpSession session;
   @ModelAttribute  
   public void setReqAndRes(HttpServletRequest request, HttpServletResponse response){  
          this.request = request;  
          this.response = response;  
          this.session = request.getSession();  
   }  
说明:ModelAttribute的作用

2:也可以直接在方法参数上声明:
public String hello(HttpServletRequest request,HttpServletResponse response)

Struts2获取request和response
1:实现org.apache.struts2.interceptor.ServletResponseAware接口

2:HttpServletResponse response = (HttpServletResponse)
ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);
HttpServletRequest request = (HttpServletRequest)
ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);


3:HttpServletResponse response = ServletActionContext.getResponse()

Struts2,springMVC获取request和response

标签:

原文地址:http://www.cnblogs.com/zhoucx66/p/5580473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!