FileDocCategorySizeDatePackage
SessionListener.javaAPI DocGlassfish v2 API6039Fri May 04 22:34:14 BST 2007listeners

SessionListener

public final class SessionListener extends Object implements HttpSessionListener, ServletContextListener, HttpSessionAttributeListener
Example listener for context-related application events, which were introduced in the 2.3 version of the Servlet API. This listener merely documents the occurrence of such events in the application log associated with our servlet context.
author
Craig R. McClanahan
version
$Revision: 1.3 $ $Date: 2007/05/05 05:34:13 $

Fields Summary
private ServletContext
context
The servlet context with which we are associated.
Constructors Summary
Methods Summary
public voidattributeAdded(javax.servlet.http.HttpSessionBindingEvent event)
Record the fact that a servlet context attribute was added.

param
event The session attribute event



    // --------------------------------------------------------- Public Methods


                         
        

	log("attributeAdded('" + event.getSession().getId() + "', '" +
	    event.getName() + "', '" + event.getValue() + "')");

    
public voidattributeRemoved(javax.servlet.http.HttpSessionBindingEvent event)
Record the fact that a servlet context attribute was removed.

param
event The session attribute event


	log("attributeRemoved('" + event.getSession().getId() + "', '" +
	    event.getName() + "', '" + event.getValue() + "')");

    
public voidattributeReplaced(javax.servlet.http.HttpSessionBindingEvent event)
Record the fact that a servlet context attribute was replaced.

param
event The session attribute event


	log("attributeReplaced('" + event.getSession().getId() + "', '" +
	    event.getName() + "', '" + event.getValue() + "')");

    
public voidcontextDestroyed(javax.servlet.ServletContextEvent event)
Record the fact that this web application has been destroyed.

param
event The servlet context event


	log("contextDestroyed()");
	this.context = null;

    
public voidcontextInitialized(javax.servlet.ServletContextEvent event)
Record the fact that this web application has been initialized.

param
event The servlet context event


	this.context = event.getServletContext();
	log("contextInitialized()");

    
private voidlog(java.lang.String message)
Log a message to the servlet context application log.

param
message Message to be logged


	if (context != null)
	    context.log("SessionListener: " + message);
	else
	    System.out.println("SessionListener: " + message);

    
private voidlog(java.lang.String message, java.lang.Throwable throwable)
Log a message and associated exception to the servlet context application log.

param
message Message to be logged
param
throwable Exception to be logged


	if (context != null)
	    context.log("SessionListener: " + message, throwable);
	else {
	    System.out.println("SessionListener: " + message);
	    throwable.printStackTrace(System.out);
	}

    
public voidsessionCreated(javax.servlet.http.HttpSessionEvent event)
Record the fact that a session has been created.

param
event The session event


	log("sessionCreated('" + event.getSession().getId() + "')");

    
public voidsessionDestroyed(javax.servlet.http.HttpSessionEvent event)
Record the fact that a session has been destroyed.

param
event The session event


	log("sessionDestroyed('" + event.getSession().getId() + "')");