1. 在web容器中设置(此处以tomcat为例)
在tomcat\conf\web.xml中设置,以下是tomcat 中的默认配置:
- <!-- ==================== Default Session Configuration ================= -->
- <!-- You can set the default session timeout (in minutes) for all newly -->
- <!-- created sessions by modifying the value below. -->
- <session-config>
- <session-timeout>30</session-timeout>
- </session-config>
Tomcat默认session超时时间为30分钟,可以根据需要修改,负数或0为不限制session失效时间。
2. 在工程的web.xml中设置
- <!-- 时间单位为分钟 -->
- <session-config>
- <session-timeout>15</session-timeout>
- </session-config>
3. 通过java代码设置
session.setMaxInactiveInterval(30*60);//以秒为单位
三种方式优先级:1 < 2 <3
配置Session超时时间
本文介绍了如何在Tomcat容器及应用程序中配置Session超时时间,包括在tomcat的web.xml中设置默认Session超时时间、在应用web.xml中覆盖默认设置以及通过Java代码动态设置Session超时时间的方法。
220

被折叠的 条评论
为什么被折叠?



