RequestContextHolder 获取request

RequestContextHolder 获取request

public HttpServletRequest getRequest() {
            return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
     }
     
     
     
     
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
 public ServletContext getServletContext() {
            return ContextLoader.getCurrentWebApplicationContext().getServletContext();
    }
     
     
     
     
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
    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();  
    }
     
     
     
     
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

写入参数的就不多说了

@RequestMapping("/path")
public void go(HttpServletRequest req, HttpServletResponse resp){
  
}
     
     
     
     
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
(function () { ('pre.prettyprint code').each(function () { var lines = (this).text().split(\n).length;var numbering = $('
    ').addClass('pre-numbering').hide(); (this).addClass(hasnumbering).parent().append( numbering); for (i = 1; i

    你可能感兴趣的:(springmvc)