用户关闭浏览器但未注销时,如何查看注销时间?

因此,我实现了从here提取的HttpSessionBindingListener并添加了Listener in web.xml,但关闭浏览器后未将注销时间插入数据库。有什么建议请问我哪里错了?

logout.jsp

 <%
    ObjectWillBeInSession owi = new ObjectWillBeInSession();
    owi.setProperty1("I am a value for Property1");
    owi.setProperty2("I am a value for Property2");
    //this will call HttpSessionBindingListener's
    //valueBound method for the object
    session.setAttribute("owi", owi);

    //this will call HttpSessionBindingListener's
    //valueUnbound method for the object
    session.removeAttribute("owi");
        //INSERT INTO DB.......BUT IT IS NOT WORKING
 %>

最佳答案

关闭浏览器不会触发对服务器的任何请求,因此您无法知道用户已关闭其浏览器。
您可以使用侦听器来使会话超时,然后在发生这种情况时存储当前时间。不过,会话通常会在客户端发出最后一个请求后的几个小时后过期。

10-02 22:39