• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session End in JSP

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic