springmvc 获取request response

RequestContextHolder 获取request

public HttpServletRequest getRequest() {
            return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
     }
 public ServletContext getServletContext() {
            return ContextLoader.getCurrentWebApplicationContext().getServletContext();
    }
    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();  
    }

写入参数的就不多说了

@RequestMapping("/path")
public void go(HttpServletRequest req, HttpServletResponse resp){
  
}

你可能感兴趣的:(JAVA,spring)