切面处获取
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
HttpServletRequest request = servletRequestAttributes.getRequest();
web.xml
方案一:
<filter>
<filter-name>springRequestFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springRequestFilter</filter-name>
<url-pattern>/your-url/*</url-pattern>
</filter-mapping>
方案二:
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
参考资料:
1、null pointer exception from Session
https://stackoverflow.com/questions/13168648/null-pointer-exception-from-session
2、@Spring MVC 中几种获取request和response的方式
https://www.cnblogs.com/winner-0715/p/6270513.html