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

1) Timeout in the deployment descriptor (web.xml)

以分钟为单位

代码如下 复制代码

20

上面这种设置,对整个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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值