Forums Register Login

Session End in JSP

+Pie Number of slices to send: Send
hi friends ,
is there is any possibility to capture the event of a session end from the server side.this is neede to terminate the files created during the session.so after the sessionthose temp files have to be cleared.this can be done only if we know about when a session ends.so please friends if any body can throw some light on this it will be more help full.
with regards
Venkat
+Pie Number of slices to send: Send
Yes you can provide for handling of resources when a session is invalidated due to time-out or whatever. Look up the API for the SessionBindingListener interface.
You can attach an object that implements this interface to a session - when the session is invalidated, the method:
valueUnbound( HttpSessionBindingEvent evt )
is called - you can use the information in the event to dispose of resources, log things, whatever.
Bill
------------------
author of:
+Pie Number of slices to send: Send
Dear Bill,
Thank you very much for kind reply. we have got 50% of your concept,if you don't mind can you please explain me more on this.
Thanks again.
Venkat
+Pie Number of slices to send: Send
Let me elaborate what brogden has said...
1. Create a custom class(to recieve call back events) that implements HttpSessionBindingListener.
2.Use the public void valueBound(HttpSessionBindingEvent event){} for recieving callback events. One can code his cleanup logic here...
Just in case you might it find it useful..i have below src code that logs user types into a log file when he ends session.
<pre>
package com.xxx.common;
import javax.servlet.http.*;
import com.xxx.report.Logger;
import com.xxx.search.SearchCacheCleanup;
/**
* This class tracks and logs system users in an HttpSession.
* It should be created and added to the session attribues when
* the user logs in to the system.
* @author M.P.Reddy
* @created 31 March 2001
*/
public class SessionMonitor implements HttpSessionBindingListener
{
String sessionId;
String userId;
String userFullName;
String userCompanyName;
int userType;

/**
* Build a session monitor using user data.
*
* @param userId
* @param userFullName
* @param userCompanyName
* @param userType
*/
public SessionMonitor( String sessionId, String userId, String userFullName,
String userCompanyName, int userType ) {
this.sessionId = sessionId;
this.userId = userId;
this.userFullName = userFullName;
this.userCompanyName = userCompanyName;
this.userType = userType;
}

/**
* Create a log entry when the user logs into the system.
* This method is called by the session when this object
* is added to the session attribute list.
*
* @param event
*/
public void valueBound(HttpSessionBindingEvent event) {
if ( userIsBuyer() ) {
Logger.logUserLogin( userId, userFullName,
userCompanyName, Integer.toString( userType ) );
//System.out.println("session beginning for " + userFullName );

}
}

/**
* Create a log entry when the user logs out of the system
* or when the session expires.
* This method is called by the session when this object
* is removed from the session attribute list.
*
* @param event
*/
public void valueUnbound(HttpSessionBindingEvent event) {
if ( userIsBuyer() ) {
Logger.logUserLogout( userId, userFullName,
userCompanyName, Integer.toString( userType ) );
//System.out.println("session ending for " + userFullName );
SearchCacheCleanup.cleanSearchCacheBySessionId(sessionId);
}
}

/**
* Determines if the user is a buyer.
*
* @return
*/
private boolean userIsBuyer() {
return userType == Constants.USER_TYPE_BUYER_MANAGER | |
userType == Constants.USER_TYPE_BUYER_SUPERVISOR | |
userType == Constants.USER_TYPE_BUYER_PROJECT_USER;
}

public String getUserCompanyName()
{
return this.userCompanyName;
}

public String getUserFullName()
{
return this.userFullName;
}

public String getUserId()
{
return this.userId;
}

public int getUserType()
{
return this.userType;
}

public String getSessionId()
{
return this.sessionId;
}
public void setSessionId(String sessionId)
{
this.sessionId = sessionId;
}
}
</pre>
Hope this helps!
cheers,
mpr
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1031 times.
Similar Threads
Can we invoke hibernate through session beans
capturing session ending event in server
How to find end of file in java
Creating an instance of hibernatedoa from stateless session bean
upload in jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:02:47.