因为是使用spring mvc来作项目,所以脱离了HttpServletRequest做为参数,不可以直接使用request,要想使用request能够使用下面的方法:html
在web点xml中配置一个监听java
- <listener>
- <listener-class>
- org.springframework.web.context.request.RequestContextListener
- </listener-class>
- </listener>
以后就能够在程序使用了web
- HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest()