aspose file tools*
The moose likes Servlets and the fly likes Session End in JSP 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 » Servlets
Bookmark "Session End in JSP" Watch "Session End in JSP" New topic
Author

Session End in JSP

Venkatesh Rajendran
Ranch Hand

Joined: May 17, 2001
Posts: 59
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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:
Venkatesh Rajendran
Ranch Hand

Joined: May 17, 2001
Posts: 59
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
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session End in JSP