Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Closing browser clicking on close button.  RSS feed

 
S Babs
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do invalidate the HttpSession object in servlet, when i accidently close the browser using close button, without logging out?
urgent please....
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Closing the browser window does not send an HTTP request to the server. You'll have to depend on a session timeout to get rid of the session on the server.
 
Benny Tang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you want to perform some addition tasks when the session is invalidated, you can implement a HttpSessionListener and then register
it in the deployment descriptor.
Benny
 
Nikki Aniban
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
When you click the close button of a browser, the onUnload function is automatically called. So you can define something like this in your HTML
<body onUnload="invalidateSession()">
But there is a catch to this. The onUnload is called whenever the user leaves your page. So if the user simply clicks on a link or submits a form, his session will also be invalidated! Luckily for you, a really good hacker found a workaround for this problem.
But if you ask me, I would go with Ron's suggestion to just let the session timeout do its thing. Hope this helps!
- Nikki
 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I agree session timeout is a good option. But i heard that if browser closes it will automatically invalidate that session. Isn't true in this case?
Regards,
M.S.Raman
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i heard that if browser closes it will automatically invalidate that session. Isn't true in this case?

This is never true. See Ron's response above. The server has no idea that the browser has been closed.
bear
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a better quetion is WHY. Is the session consuming too much memory? Do you need to release some sort of disconnected locks?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36440
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree session timeout is a good option. But i heard that if browser closes it will automatically invalidate that session. Isn't true in this case?

As pointed out in the above posts, the session is not really invalidated. It stays in memory until it expires. However, it is "invalidated" from the user's point of view in that the user cannot access the session ever again. Opening a new browser window will get a different session.
 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear Bibeault & Dana Hanna & Jeanne Boyarsky,
Thanks for you. I misunderstood S.Babs's query that on closing the browser(last window) he is still able to use the session object.
Thanks & Regards,
M.S.Raman
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!