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