简体   繁体   English

检索注销时间而不注销

[英]retrieve logout time without logout

how can i see logout time when user closes the browser without logout? 用户关闭浏览器但未注销时,如何查看注销时间?

So i implemented HttpSessionBindingListener taken from here and added Listener in web.xml but logout time is not being inserted into database after closing browser. 因此,我实现了从此处获取的HttpSessionBindingListener ,并Listener in web.xml添加了Listener in web.xml但是关闭浏览器后未将注销时间插入数据库。 Any suggestion please where i am wrong? 有什么建议请问我哪里错了?

logout.jsp 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
 %>

Closing the browser does not trigger any request to the server, so there is no way you can know that the user closed his browser. 关闭浏览器不会触发对服务器的任何请求,因此无法知道用户已关闭其浏览器。 You can use a listener to way for the session to time out and then store the current time when that happens. 您可以使用侦听器来使会话超时,然后在发生这种情况时存储当前时间。 Session typically expire hours after the last request from the client, though. 不过,会话通常会在客户端发出最后一个请求后的几个小时后过期。

您可以使用JavaScript的window.onbeforeunload将AJAX请求发送到servlet,以记录用户关闭浏览器并在会话对象中执行所需操作的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM