Struts2,springMVC获取request和response

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()
上一篇:C#获取当前路径的7种方法


下一篇:PHP中获取星期的几种方法