如何在SpringMVC中獲取request對象web
1.註解法spring
Java代碼 收藏代碼xml
@Autowired 對象
private HttpServletRequest request; get
2. 在web.xml中配置一個監聽io
Xml代碼 收藏代碼class
<listener> 配置
<listener-class> List
org.springframework.web.context.request.RequestContextListener request
</listener-class>
</listener>
以後在程序裏能夠用
Java代碼 收藏代碼
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
3.直接在參數中引入
Java代碼 收藏代碼
public String hello(HttpServletRequest request,HttpServletResponse response)
如何在Struts2中獲取request對象
Java代碼 收藏代碼
HttpServletRequest request = ServletActionContext.getRequest();