【问题标题】:State of HttpSession instance after timeout?超时后HttpSession实例的状态?
【发布时间】:2013-09-03 23:10:56
【问题描述】:

是什么让 HttpSession 实例在超时后过期也被检查了

 if(session!=null){

        System.out.println("The instance is not null");
        }else{
        System.out.println("The instance is null");
        }

每次执行 if 块时。

【问题讨论】:

    标签: java servlets httpsession


    【解决方案1】:
    • 要使会话到期,请使用session.invalidate()。这将 确保您的会话已过期。
    • 即使会话无效,也不一定意味着它是 null

    【讨论】:

      【解决方案2】:

      如果您使用HttpServletRequest.getSession(false),那么如果HttpSession 对象无效,则不会创建它。

      在这种情况下,session 可以是 null

      【讨论】:

        猜你喜欢
        • 2013-03-12
        • 2010-11-20
        • 2022-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-22
        • 2013-04-15
        • 2016-08-26
        相关资源
        最近更新 更多