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

在SpringMVC中获取request对象

时间:2016-10-11 11:55:00      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

1.注解法

 

 

Java代码  技术分享
  1. @Autowired  
  2. private  HttpServletRequest request;  

 

 

2. 在web.xml中配置一个监听

 

Xml代码  技术分享
  1. <listener>    
  2.         <listener-class>    
  3.             org.springframework.web.context.request.RequestContextListener    
  4.         </listener-class>    
  5. </listener>    

 

之后在程序里可以用

 

 

Java代码  技术分享
  1. HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();    

 

 3.直接在参数中引入

Java代码  技术分享
  1. public String hello(HttpServletRequest request,HttpServletResponse response)  

 

 

 

 

如何在Struts2中获取request对象

 

Java代码  技术分享
  1. HttpServletRequest request = ServletActionContext.getRequest();  

在SpringMVC中获取request对象

标签:

原文地址:http://www.cnblogs.com/huhuixin/p/5948390.html

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