How can I invalidate a session on browser close using JSP/Servlets?
Asked
Active
Viewed 2,079 times
2 Answers
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