WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.servlets.lifecycle

This example demonstrates how to write Servlet LifeCycle Listeners.

See:
          Description

Class Summary
LifeCycleListener LifeCycleListener is a servlet listener class that implements the javax.servlet.ServletContextListener interface.
SessionAttributeListener SessionAttribueListener is a servlet listener class that implements the javax.Servlet.http.HttpSessionAttributeListener interface.
SessionListener SessionListener is a servlet listener class that implements the javax.Servlet.http.HttpSessionListener interface.
 

Package examples.servlets.lifecycle Description

This example demonstrates how to write Servlet LifeCycle Listeners.

The lifeCycleWebApp is an example of an administrative utility that can be used to list all the Active sessions in a WebApplication and list session related information such as the creationTime, the lastAccessedTime etc. This demonstrates the application lifecycle event listening features introduced in the Servlet 2.3 specification.

See:
          Description

Additional Resources for examples.servlets.lifecycle
build.xml The Ant build script that assembles and deploys the application.
index.html Welcome page for the lifeCycle Web Application.
Invalidate.jsp This Java Server Page removes invalid sessions from the session list. It should only be called from List.jsp.
List.jsp This Java Server Page lists all the active sessions, and has a link to invalidate each session.
Session.jsp This Java Server Page is used for testing the Web Application by adding attributes to the session.
web.xml Web Application deployment descriptor. This descriptor configures the listeners the webapp uses and a welcome file for the application.
 

Package examples.servlets.lifecycle Description

The Web Application lifeCycleWebApp Is an example of using Servlet Context and Http Session Listeners in your web applications. In this example, the listeners just log to standard out messages about what is happening to the application, but you could execute any code in these listening methods.

Perform the following steps in order to build and run the example:

  1. Build the example
  2. Run the example

Build the Example

  1. Set up your development shell as described in Setting up your environment.

  2. Compile the example by executing an ant build script.

Run the Example

  1. Start WebLogic Server with the examples configuration. Notice the messages logged from the LifeCycleListener.java class when the application is deployed.

  2. Load the lifeCycleWebApp Web Application into a browser using a URL such as:
      http://hostname:port/lifeCycleWebApp
    where:
    hostname
    Host name of the WebLogic Server
    port
    Port where the WebLogic Server is listening for connections

  3. Click on the "click here" link. It will take you to the Session.jsp page. Notice that a Http Session has been created, and is logged to standard out by the SessionListener class.
  4. Add and delete some attributes to the Http Session. Again look at the standard out from the server, and see the logging from the SessionAttributeListener as it describes the adds/deletes.
  5. Click on the "List.jsp" link. This jsp page lists all the active sessions, and gives you an option to invalidate each one. Invalidate your session, and again check the standard out from the server. You will see the output from the SessionListener class from the sessionDestroyed method.
  6. Finally, undeploy the lifeCycleWebApp using the weblogic server console. This will call the contextDestroyed method of the LifeCycleListener class, and log the messages to standard out.



Documentation is available at
http://e-docs.bea.com/wls/docs70

Copyright © 2002 BEA Systems, Inc. All Rights Reserved.