SpringMVC中获取request与response对象

1:使用 注解 @Autowired private  HttpServletRequest request; 或在方法中public String (HttpServletRequest req,HttpServletResponse resp);

 

2:  在web点xml中配置一个监听

 

<listener>  
        <listener-class>  
            org.springframework.web.context.request.RequestContextListener  
        </listener-class>  
</listener>  

然后使用:

/** 获取HttpServletRequest */
public static HttpServletRequest getRequest() {
	return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();  
}

 

 3:

如何在Struts2中获取request对象:

HttpServletRequest request = ServletActionContext.getRequest();

你可能感兴趣的:(springMVC)