1.最簡單的方式(註解法)html
1web 2spring |
|
2.最麻煩的方法xml
a. 在web.xml中配置一個監聽htm
<listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
b.以後在程序裏能夠用對象
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
3.最直接的方法blog
1ci |
|
贈送一個如何在Struts2中獲取request對象
HttpServletRequest request = ServletActionContext.getRequest();