ㄓㄤㄑㄧㄤ

如何在SpringMVC中获取request对象

1.注解法

@Autowired  
private  HttpServletRequest request; 
<listener>    
        <listener-class>    
            org.springframework.web.context.request.RequestContextListener    
        </listener-class>    
</listener>

之后在程序里可以用

HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();  

 3.直接在参数中引入

public String hello(HttpServletRequest request,HttpServletResponse response)

如何在Struts2中获取request对象

HttpServletRequest request = ServletActionContext.getRequest();

 

posted @ 2016-08-29 09:50  ㄓㄤㄑㄧㄤ  阅读(311)  评论(0编辑  收藏  举报
哈哈,页脚部分。