This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session handling in case of abnormal shutdown

 
Soumik Basu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • 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.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
KedariNadh vsilla
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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 ..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Sri Anand
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could Use Session ID and Username to see if the started another session because of abnormal shutdown
 
Subrata Biswas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic