- 时间:2020-05-17 07:56 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:Java中设置session超时(失效)的三种方法
[b]1.在web容器中设置(此处以tomcat为例)[/b]
在tomcat-5.0.28confweb.xml中设置,以下是tomcat 5.0中的默认配置:
<!-- ==================== 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失效时间。
[b]2. 在工程的web.xml中设置[/b]
<!-- 时间单位为分钟 -->
[html] view plaincopy
<session-config>
<session-timeout>15</session-timeout>
</session-config>
[b]3. 通过java代码设置[/b]
session.setMaxInactiveInterval(30*60);//以秒为单位