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
//获取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
上一篇: MySQL中的锁(表锁、行锁)
下一篇: 如何查看mysql数据库的引擎