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 Clean up after sessions end Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Clean up after sessions end" Watch "Clean up after sessions end" New topic
Author

Clean up after sessions end

L. Riley
Greenhorn

Joined: Mar 20, 2001
Posts: 28
I have the need to do some cleanup work after a session ends. In ASP (oh my!) this can be done using session.onEnd in the global.asa.
How can this be done in JSP?
mounika paruchuri
Greenhorn

Joined: Feb 12, 2002
Posts: 26
Hi Liz,
do you want to know when the session is destroyed ,that is ends?? If that is the case then check out API documentation for HttpSessionListener interface in package javax.servlet.http
Mounika.
L. Riley
Greenhorn

Joined: Mar 20, 2001
Posts: 28
Yes...I want to clean up some records in a table if the user ends the session. Do you know of another place that describes this more clearly than the API?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Everything you could ever want to know: Java Servlet 2.3 Specification.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
You can use class which act as session listener in your application and register it in deployment descriptor (web.xml) . It extends HttpSessionListener and implements method sessionCreated(HttpSessionEvent se) and sessionDestroyed(HttpSessionEvent se).
You can put your code for clean up in method sessionDestroyed().
The web container will invoke or notify sessionDestroyed() when your application invalidates sessions or the sessions are timeout.
Hope this help...
Correct me if i am wrong...
daniel
[ April 02, 2003: Message edited by: Fisher Daniel ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
If you make your class that contains the data a SessionBindingListener, the object will be notified when the session is destroyed and you will have the data right there. You don't have to register a SessionBindingListener.
Bill
Mehta Saryu
Greenhorn

Joined: Dec 12, 2002
Posts: 13
session.removeAttribute("sessionname")


Saryu Mehta
L. Riley
Greenhorn

Joined: Mar 20, 2001
Posts: 28
No...I want to delete some records from a database if the session ends...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clean up after sessions end