本文用于记录使用Spring MVC中的零散手札
1.在普通java类中获取HttpServletRequest对象
在web.xml的listener节点加入
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener </listener-class>
</listener>
//需要使用的地方如下方法获取
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();