如何检查会话是否无效
如何检查会话是否无效? API 中没有方法。
它和isNew()
一样吗? 如果不是的话有什么区别?
How to check if a session is invalid or not?
There is no method in the API.
Is it the same as isNew()
? And what is the difference if not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想知道它是否基于请求有效:
如果您存储了对会话的引用并且需要验证,我会
If you want to know whether it valid based on a request:
If you have stored a reference to the session and need to validate I would
仅当客户端尚未接受此会话时,
isNew()
才为 true(即,它刚刚创建,并且 JSESSIONID 尚未发送,或者即使发送了,客户端也没有发送它)返回,所以服务器不知道它并创建了另一个会话)isNew()
is true only if this session wasn't yet accepted by client (i.e. it was just created, and JSESSIONID wasn't sent yet, or if it was sent, client didn't send it back, so server doesn't know about it and created another session)出于所有意图和目的,是的。 但是,如果在同一请求响应周期中无效的会话上调用,它将抛出 IllegalStateException。
For all intents and purposes, yes. However, it will throw an IllegalStateException if called on a session invalidated in the same request-response cycle.