• 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 do i know when browser is closed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
how would i know when user closes the browser.because i have to roll back some of the transactions when user closes the browser. from html i can use onunload method .but i want to know browser closing event at server side.At the same time how can i know particular session is inactive? our session timeout period is about 15 minutes so i can't wait for session timeout and rollback.
Thanks in advance
[ March 08, 2004: Message edited by: Rehana Shaik ]
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Relying on browser events using JavaScript is inherently unsafe - I'd recommend you don't use it. Rather than trying to roll back a transaction when the browser is closed, include some confirmation action to commit the whole transaction once the user has done whatever you need them to do - if it is never reached, then the transaction is never committed.
You will only know if the session is inactive if it has timedout. Reduce the size of your session timeout.
[ March 08, 2004: Message edited by: cluck cluck ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Cluck Cluck"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Good Answer to the question though.
Mark
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Leaving a transaction open and waiting for user intervention is usually a bad idea. You might want to re-think what you're doing. If you can (if it's not a lot of data), you might want to gather up everything you need to perform the transaction and store it in the session. Then, at the end, you use that information to perform the entire transaction during one request. If the user closes their browser or their session times out, the data for the transaction is lost. You could actually save the data in the database (marking it as temporary or provisional somehow) and listen for session timeout events (via an HttpSessionListener) to clean it up. However you do it, I would NOT leave open a JDBC connection to the database while waiting for the user to do something. That can be quite a resource hog, especially if your session-timeout value is large. Just my $0.02.
 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

At the same time how can i know particular session is inactive?


Add a class implementing HttpSessionListener interface in your application. this interface has 2 methods -
1. sessionCreated
2. sessionDestroyed
when your session gets inactive, sessionDestroyed() method would be called to indicate the same.
Dont forget to register this class as listener in your web.xml.
I hope, this helps. :-)
reply
    Bookmark Topic Watch Topic
  • New Topic