• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

session handling in case of abnormal shutdown

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having one application with 4-5 jsp and I am maintining sessions in between all pages,I am also writing the record for the user who has loggedIn in a .properties file. Now when the user logs out then the user name should get removed from that .properties file, if he logs out properly then i can write methods to remove his name.
But how to do the same job when the user directly closes the browser or the session times out?
I need to write some code when the user session gets killed or times out.
I need some help in how and where to handle the timeout or session killing event.
any help will be regarded with high spirits.
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Need to do two things

First set a session timeout in web.xml

This tells the container to invalidate the session after 15 mins of inactivity.

Then add a HttpSessionListener
check this out

HttpSessionListener

The listener will be added to web.xml as

where com.example.MySessionListener is a class implementing HttpSessionListener. Write you logic in sessionDestroyed method.

Hope this solves your problem.
[ November 19, 2008: Message edited by: Amol Nayak ]
 
Soumik Basu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.
But could you please tell me how to handle the situation when the user directly closes the browser and hence kills the session.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Soumik Basu:
Thanks for your reply.
But could you please tell me how to handle the situation when the user directly closes the browser and hence kills the session.



The listener will handle it. Also sometimes Javascript is used to detect a browser window close.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Soumik Basu:
Thanks for your reply.
But could you please tell me how to handle the situation when the user directly closes the browser and hence kills the session.



Closing a browser will not kill a session.
It may make it impossible for the user to access that session but it will not immediately kill it. The orphaned session will remain on the server until it times out.
 
Soumik Basu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have written this code in my jsp file after importing the sessionBindListener class.I am writing my sessionBindListener.java class below.


in my web.xml I had to add the following


after 1 min my session gets invalidated and in the console I can see session unbounded getting printed.
For browser closing i have to write the following javascript code in my jsp page

and in close.jsp I am writing the code for session invalidation.

Its working fine.
But I have to add this page in a portal and this portal will run ion browser.
So can anyone please tell me how to handle the browser closing of a portal.
I am using BEA weblogic8.1 portal server.
[ November 26, 2008: Message edited by: Soumik Basu ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While closing the window ,we can call a javascript function from that we can send a request to actionclass with in that we can close all the connection ..
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by KedariNadh vsilla:
While closing the window ,we can call a javascript function...


No, we can't. There is no JavaScript event that is triggered upon closing the browsers.
 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could Use Session ID and Username to see if the started another session because of abnormal shutdown
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
really it is interesting. yes I have done it in one of my application using Ajax call. The idea you came up with it's close to mine too. You have used a close.jsp instead make a Ajax call. your request should go to a servlet wher your logic should be placed to remove the entry from your property file.It should work as it is working for me. I am using WSAD5,JAVA1.4,Struts1.2.

Best of luck.
 
machines help you to do more, but experience less. Experience this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic