This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to know if user closes the browser window in servlets

 
GK
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I know thru servets if a user closes its browser window?
Gunjan
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
As far as I know, it's not possible.
 
Andre Moo
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
DC Dalton
Ranch Hand
Posts: 287
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic