方法一:
@Autowired
private HttpServletRequest request;
方法二:
public void test( HttpServletRequest request,HttpServletReponse reponse){
}
方法三:加入监听器
1,在web.xml 配置如下
<listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
2、在controller获取如下:
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
时间: 2024-10-14 17:15:58