springMVC获取request和response1:在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和response1:实现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()
时间: 2024-10-28 21:07:01