欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring 获取HttpSession ,HttpServletRequest ,HttpServletResponse

程序员文章站 2022-05-24 14:13:01
...
ServletRequestAttributes servletRequestAttributes =(ServletRequestAttributes)RequestContextHolder.currentRequestAttributes();
//获取session
   HttpSession s = servletRequestAttributes.getRequest().getSession();
   //请求
   HttpServletRequest request = servletRequestAttributes.getRequest();
   //应答
   HttpServletResponse response = servletRequestAttributes.getResponse();
  
   System.out.println("spring session= "+s.getCreationTime());
   System.out.println("id:"+s.getId());
   System.out.println("active:"+s.getMaxInactiveInterval());
   System.out.println("真实路径:"+request.getRealPath("/"));
   System.out.println("response:"+response);


web.xml 中添加
<listener> 
        <listener-class> 
            org.springframework.web.context.request.RequestContextListener 
        </listener-class> 
</listener>


日志:

spring session= 1493713201202
id:82B6E2359779D42C97F97790E0EF8C4C
active:1800
真实路径:E:\gradlepro\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\tjdjd\
response:org.apache.catalina.connector.ResponseFacade@122fbe4
相关标签: sping