如何检查会话是否无效 [英] How to check if a session is invalid

查看:116
本文介绍了如何检查会话是否无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查会话是否无效?
API中没有方法

How to check if a session is invalid or not? There is no method in the API.

是否与 isNew()相同?如果没有,有什么区别?

Is it the same as isNew()? And what is the difference if not?

推荐答案

如果你想知道它是否有效,请根据请求:

If you want to know whether it valid based on a request:

request.isRequestedSessionIdValid()

  or

HttpSession sess = request.getSession(false);
if (sess != null) {
   // it's valid
}

如果您存储了对会话的引用并需要验证我会

If you have stored a reference to the session and need to validate I would

try {
  long sd = session.getCreationTime();
} catch (IllegalStateException ise) {
  // it's invalid
}

这篇关于如何检查会话是否无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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