当会话被视为已访问 [英] When session is considered accessed

查看:51
本文介绍了当会话被视为已访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用 HttpServletRequest.getSession(boolean create)是否会导致会话的上次访问时间被更新?怎么样 getId()方法,甚至调用 getLastaccessedtime().简而言之,访问 HttpSession 的标准是什么,导致 getLastAccessedTime 被更新

Does calling HttpServletRequest.getSession(boolean create) cause the last accessed time of the session to be updated? What about getId() method or even calling getLastaccessedtime(). In brief, what is the criteria of accessing the HttpSession that cause the getLastAccessedTime to be updated

推荐答案

Tomcat

The Tomcat javadoc says this:

"返回客户端最后一次发送与此会话相关联的请求的时间,以格林尼治标准时间1970年1月1日午夜以来的毫秒数为单位,并以容器收到请求的时间为准.

"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.

应用程序执行的操作(例如获取或设置与会话相关联的值)不会影响访问时间."

因此,根据javadoc的说法,对您问题的答案是(应该):

So, based on what the javadoc says, the answers to your questions are (should be):

问:调用HttpServletRequest.getSession(boolean create)是否会导致会话的上次访问时间被更新?

Q: Does calling HttpServletRequest.getSession(boolean create) cause the last accessed time of the session to be updated?

A:根据javadoc,不是(但请参阅下文)

A: According to the javadoc, No. (But see below)

问:怎样使用getId()方法,甚至调用getLastaccessedtime().

Q: What about getId() method or even calling getLastaccessedtime().

A:不.

问:简而言之,访问HttpSession的标准是什么导致getLastAccessedTime被更新.

Q: In brief, what is the criteria of accessing the HttpSession that cause the getLastAccessedTime to be updated.

A:请参见上文.它记录了上次客户端请求会话的时间.

A: See above. It records the time of the last client request for the session.

请注意,实际行为可能取决于Servlet实现.例如,根据Tomcat 7源代码(

Note that the actual behavior is liable to depend on the Servlet implementation. For instance, according to the Tomcat 7 source code (7.0.39.2), a getSession(boolean) call will update the access time:

  1. 当当前 Session 尚未缓存在 Request 中并且请求的会话管理器能够将sessionid映射到有效的 Session

  1. when the current Session is not already cached in the Request AND the request's session manager is able to map the sessionid to a valid Session, or

create true 并且创建 Session 时.

尚不清楚方案1是否真的可能发生在来自应用程序代码的调用中,但是方案2当然可以.这意味着创建 Session 算作是访问"....这很有意义.

It is not clear whether scenario 1. could actually happen in a call from application code, but scenario 2. certainly could. It means that creating the Session counts as an "access" ... which makes sense.

这篇关于当会话被视为已访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆