session超时

设置Session超时时间方式:

方式一:
 在web.xml中设置session-config如下:
<session-config>
  <session-timeout>2</session-timeout>
</session-config>

客户端连续两次与服务器交互间隔时间最长为2分钟,2分钟后session.getAttribute()获取的值为空。

方式二:
 在Tomcat的/conf/web.xml中session-config,默认值为:30分钟
 <session-config>
    <session-timeout>30</session-timeout>
 </session-config>

方式三:
 在Servlet中设置
 HttpSession session = request.getSession();
 session.setMaxInactiveInterval(60);//单位为秒

说明:
 优先级:Servlet中API设置 > 程序/web.xml设置 > Tomcat/conf/web.xml设置

原文地址:https://www.cnblogs.com/liluredhat/p/6773583.html