在SpringMVC中获取request对象的几种方式
1.最简单的方式(注解法)
@Autowired
private HttpServletRequest request;
2.最麻烦的方法
a. 在web.xml中配置一个监听
<listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
b.之后在程序里可以用
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
3.最直接的方法
public String hello(HttpServletRequest request,HttpServletResponse response)
赠送一个如何在Struts2中获取request对象
HttpServletRequest request = ServletActionContext.getRequest();
转:http://www.cnblogs.com/xusir/p/4135419.html
本文介绍了在SpringMVC框架中获取HttpServletRequest对象的三种主要方法:使用@Autowired注解、通过RequestContextHolder和作为方法参数直接传递。此外还简要提到了在Struts2中获取request对象的方式。
972

被折叠的 条评论
为什么被折叠?



