FileDocCategorySizeDatePackage
SessionListener.javaAPI DocApache Tomcat 6.0.144552Fri Jul 20 04:20:32 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: 500674 $ $Date: 2007-01-28 00:15:00 +0100 (dim., 28 janv. 2007) $

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);

    
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() + "')");