java - 以编程方式确定 Java session 超时

标签 java jsp servlets

Java servlet/jsp 是否有任何方法可以确定网络服务器的 session 超时(以秒、分钟等为单位)?我尝试查看 HttpSession 和系统 API,但没有看到任何用于确定网络服务器 session 超时的属性。我知道这个值是在 web.xml 中设置的,但是我正在设计一个 java 库,需要通过代码来确定它。

注意:我正在为通用网络服务器设计,不能依赖供应商特定的扩展。

最佳答案

HttpSession.getMaxInactiveInterval提供这个值

int getMaxInactiveInterval()

Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. After this interval, the servlet container will invalidate the session. The maximum time interval can be set with the setMaxInactiveInterval method.

A return value of zero or less indicates that the session will never timeout.

Returns: an integer specifying the number of seconds this session remains open between client requests

关于java - 以编程方式确定 Java session 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1915084/

相关文章:

java - 你能在taglib代码中使用taglib获取jsp文件的文件名吗

Java HTTP 请求消息

java - 为什么 ArrayList 没有 getSize() 而不是 size()?

Java Servlets,如何在多个转发中保持请求属性有效?

java - 如何使用JOGL库执行项目?

java - 执行 SQL UPDATE 语句后刷新 JTable

java - 使用 JSTL 提取主键

jsp - 登录时获取用户IP

javascript - Java servlet 无法读取 html select 标记名称

java - JSP目录结构