• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to know if user closes the browser window in servlets

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I know thru servets if a user closes its browser window?
Gunjan
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know, it's not possible.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, this is not a Servlet issue.
There is no way of knowing whether the user has closed the browser window regardless of the server-side technology you use - jsp/servlets/asp/coldfusion/php/perl etc.
Hence the introduction of "sessions" in languages like asp/servlets/coldfusion to try and overcome this inherent limitation due to the nature of HTTP. It is up to the developer to set a sensible session "time-out".
Technically, however, there is a very poor and very un-elegant way of determining when the browser is closed which is highly un recommended - it is possible using client-side scripting e.g JavaScript or JScript, to detect when the browser window is closing and then do something - like open another window!(you may have experienced this on annoying sites with advert popup windows) When you open up the new window, you could point it to a url which then signals to the server that the user had closed the original browser window. Make sense? I don't recommend you implement this!
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to agree with Andre 100%. I have tryed numerous versions of JavaScript to catch this event & every one of them is just loaded with bugs....Stick with sessions & session listeners & life will be much easier
 
reply
    Bookmark Topic Watch Topic
  • New Topic