码迷,mamicode.com
首页 > 编程语言 > 详细

在SpringMVC中获取request对象的几种方式

时间:2017-09-25 11:32:43      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:方式   autowired   http   struts   tco   spring   mvc   string   简单   

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();

在SpringMVC中获取request对象的几种方式

标签:方式   autowired   http   struts   tco   spring   mvc   string   简单   

原文地址:http://www.cnblogs.com/rock-wang/p/7590389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!