最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
java设置配置session过期时间的方法
时间:2022-11-14 23:25:30 编辑:袖梨 来源:一聚教程网
1) Timeout in the deployment descriptor (web.xml)
以分钟为单位
代码如下 | 复制代码 |
|
上面这种设置,对整个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 “setMaxInactiveInterval()” 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设置产生效果的优先循序是,先程序后配置,先局部后整体。
相关文章
- 霍格沃茨之遗兑换码是什么 霍格沃茨之遗最新2025兑换码 10-17
- 鸣潮仇远培养材料有哪些-仇远天赋突破材料汇总 10-17
- 辉烬锡蒙利技能是什么 锡蒙利技能介绍一览 10-17
- 伊瑟黑旗怎么样 黑旗介绍一览 10-17
- 三国天下归心马超阵容怎么搭配 马超阵容搭配推荐 10-17
- 荒原曙光雪山怎么进入 雪山进入方法 10-17