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/