简体   繁体   中英

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. Any suggestion please where i am wrong?

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,以记录用户关闭浏览器并在会话对象中执行所需操作的时间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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