1

How can I invalidate a session on browser close using JSP/Servlets?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
pal
  • 1,202
  • 6
  • 17
  • 27
  • Hi, your question seems to be a duplicate. Have a look : http://stackoverflow.com/questions/4713234/invalidate-a-session – EMM Sep 27 '11 at 08:30

2 Answers2

3

You can't do that. Set session's timeout, it will be automatically invlidated after a specific amount of time of inactivity.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
1

You can do that, but it seems like a bad thing to do.

Bind a function to the unload event of the window and make an ajax call to invalidate the session.

Using jQuery you might do this:

     $(window).unload(function()
        {
            alert("Yar, the light be fadin.");
        });

Of course, replace the alert with the ajax call you want to make.

Setting the session timeout seems like a better option.

DwB
  • 37,124
  • 11
  • 56
  • 82