springMVC中,为了方便随时获取当前的request对象,可以通过RequestContextHolder的静态方法getRequestAttributes()获取Request相关的变量,如request, response等。
HttpServletRequest request =
((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
- 通过这种方式,就不需要在接收或传递参数的时候通过定义HttpRequest或HttpResponse来获取参数了。