本文实例讲述了java设置session过期时间的实现方法,分享给大家供大家参考。具体实现方法如下:
1、Timeout in the deployment descriptor (web.xml)
以分钟为单位
<web-app ...> <session-config> <session-timeout>20</session-timeout> </session-config> </web-app>
2、Timeout with setMaxInactiveInterval()
通过编码方式,指定特定的session的过期时间,以秒为单位。例如:
HttpSession session = request.getSession(); session.setMaxInactiveInterval(20*60);
Thoughts….
This is a bit confusing , the value in deployment descriptor (web.xml) is in “minute”, but the setMaxInactiveInterval() method is accept the value in “second”. Both functions should synchronize it in future release
3、在程序中定义,单位为秒,设置为-1表示永不过期,示例代码为:
session.setMaxInactiveInterval(30*60);
希望本文所述对大家的Java程序设计有所帮助。