我想知道HttpSession究竟什么时候会过期(与销毁不同)?
我试图弄清楚 session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000) 是否会在每次请求带有相同的会话 ID 时为我提供会话到期的确切时间(以毫秒为单位)!
从javadocs:
长 getLastAccessedTime()
Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request.
int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.
假设我们有以下内容:
Treq1 - the time the container received the 1st request
(HttpSession.lastAccessedTime)
Tresp1 - the time the container sends the 1st response
Preq1 - the time period between Treq1 and Tresp1 (the time period that the server processes the 1st request
Treq2 - the time the container received the 2nd request
(HttpSession.lastAccessedTime)
Preq1req2 - the time period between Treq1 and Treq2 (the time between requests entering the container)
Presp1req2 -the time period between Tresp1 and Treq2 (the time between the 1st response exiting the container and the 2nd request entering the container)
那么现在,服务器何时将会话计算为过期?当:
1. Treq1 + maxInactiveInterval < Treq1 + Preq1req2 => maxInactiveInterval < Preq1req2
2. Tresp1 + maxInactiveInterval < Tresp1 + Presp1req2 => maxInactiveInterval < Presp1req2
这部分,the servlet container will keep this session open between client accesses
有点混乱。它是指在请求进入容器之间还是在响应退出和请求进入之间?
附带说明一下,我知道会话可能不会在到期的确切时间被销毁,但我还不知道它是否在容器中发生任何请求处理逻辑之前被销毁。我指的是持有过期会话 id 的请求。
亲切的问候,
暴君