java 会话时长,java – 当考虑访问会话时

Tomcat

javadoc说:

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

Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time.“

所以,根据javadoc的说法,你的问题的答案是(应该):

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

答:根据javadoc,没有(但见下文)

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

答:没有.

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

答:见上文.它记录上次客户端请求的时间.

请注意,实际行为可能取决于Servlet的实现.例如,根据Tomcat 7源代码(7.0.39.2),getSession(boolean)调用将更新访问时间:

>当当前会话尚未缓存在请求中时,请求的会话管理器能够将会话ID映射到有效会话,或者

>当create为true且创建会话时.

目前尚不清楚方案1是否真的可以在应用程序代码的调用中发生,但方案2当然可以.这意味着创建会话计为“访问”……这是有道理的.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值