获取HttpServletRequest几种方法

  • 代码获取

先web.xml配置:

  
          
            org.springframework.web.context.request.RequestContextListener  
          
  

然后代码获取

HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
  • spring 直接办法
public ModelAndView userLandlord(Model model, HttpServletRequest request){

}

 

  • 注解法
@Autowired
private  HttpServletRequest request;

 

你可能感兴趣的:(java)