利用Spring随时随地获得Request和Session
一、准备工作:
在web.xml中添加
1. <listener>
2. <listener-class>
3. org.springframework.web.context.request.RequestContextListener
4. </listener-class>
5. </listener>
二、使用方法:
1、方法一:通过代码实现
1. HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
2、方法二:通过注解实现:
1. @Autowired
2. private HttpServletRequest request;
标签:HttpServletRequest,web,Spring,Request,request,Session
From: https://blog.51cto.com/u_1481758/7499720