cipher
cipher

Reputation: 2484

Destroying a Session While Closing the Browser in JSP

I have a JSP WebApplication created. Sessions are used for some features which needs to be destroyed after closing the browser. While I am testing it in my browser (Mozilla), the session does not destroy . Please Help!

Upvotes: 0

Views: 2187

Answers (1)

Siddharth Tyagi
Siddharth Tyagi

Reputation: 92

You can create a service or jsp in which you can invalidate (destroy) the session.

request.getSession().invalidate()

You can send a call to this service on browser window close event through javascript like

//  window.onclose is Not available with Firefox 2 or Safari
window.onclose = function(event){
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","<your-service-url>",false);
    xmlhttp.send();
}

Upvotes: 1

Related Questions