如何在SpringMVC中获取request对象
1.注解法
- @Autowired
- private HttpServletRequest request;
2. 在web点xml中配置一个监听
- <listener>
- <listener-class>
- org.springframework.web.context.request.RequestContextListener
- </listener-class>
- </listener>
之后在程序里可以用
- HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
如何在Struts2中获取request对象
- HttpServletRequest request = ServletActionContext.getRequest();