1.在Web.xml中加入
<listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>
2.调用代码
public static HttpServletRequest getRequest() { return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); }