File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes session handling in case of abnormal shutdown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "session handling in case of abnormal shutdown" Watch "session handling in case of abnormal shutdown" New topic
Author

session handling in case of abnormal shutdown

Soumik Basu
Ranch Hand

Joined: Oct 01, 2007
Posts: 40
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

Joined: Oct 26, 2006
Posts: 218
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

Joined: Oct 01, 2007
Posts: 40
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

Joined: Jun 06, 2007
Posts: 2716
    
    6

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.


SCJP, SCWCD.
|Asking Good Questions|
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Soumik Basu
Ranch Hand

Joined: Oct 01, 2007
Posts: 40


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

Joined: Nov 26, 2008
Posts: 11
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sri Anand
Ranch Hand

Joined: Mar 06, 2005
Posts: 392
You could Use Session ID and Username to see if the started another session because of abnormal shutdown
Subrata Biswas
Greenhorn

Joined: Nov 25, 2008
Posts: 9
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.
 
wood burning stoves
 
subject: session handling in case of abnormal shutdown