java设置配置session过期时间的方法

王朝学院·作者佚名  2016-05-29
窄屏简体版  字體: 小  |  中  |  大  |  超大  

java设置配置session过期时间的方法1) Timeout in the deployment descriptor (web.xml)以分钟为单位

代码如下 复制代码 <web-app ...> <session-config> <session-timeout>20</session-timeout> </session-config></web-app>

上面这种设置,对整个web应用生效。当客户端20分钟内都没有发起请求时,容器会将session干掉。

2) Timeout with setMaxInactiveInterval()通过编码方式,指定特定的session的过期时间,以秒为单位。例如:

代码如下 复制代码 HttpSession session = request.getSession();session.setMaxInactiveInterval(20*60);

The above setting is only apply on session which call the “setM(www.111cn.net)axInactiveInterval()” method, and session will be kill by container if client doesn’t make any request after 20 minutes.

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);

Session设置产生效果的优先循序是,先程序后配置,先局部后整体from:http://www.111cn.net/jsp/Java/59186.htm

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航