|
|
| |
Application Events and Listeners
This section discusses how to configure and use Web Application events and listeners:
Overview of Application Events and Listeners
Application events provide notifications of a change in state of the servlet context (each Web Application uses its own servlet context) or of an HTTP session object. You write event listener classes that respond to these changes in state and you configure and deploy Application event and listener classes in a Web Application.
For servlet context events, the event listener classes can receive notification when the Web Application is deployed or is being undeployed (or when WebLogic Server shuts down), and when attributes are added, removed, or replaced.
For HTTP Session events, the event listener classes can receive notification when an HTTP session is activated or is about to be passivated, and when an HTTP session attribute is added, removed, or replaced.
Use Web Application events to:
Note: Application events are a new feature in the Java servlet specification, version 2.3 from Sun Microsystems. Version 2.3 is a proposed final draft of the servlet specification. If you are planning to use application events in your application, note that the specification has not been finalized and could change in the future.
The Servlet 2.3 specification is part of the J2EE 1.3 specification. To use J2EE 1.3 features, please see WebLogic Server 6.1 with J2EE 1.2 and J2EE 1.3 Functionality.
WebLogic Server 6.1 with J2EE 1.2 and J2EE 1.3 Functionality
BEA WebLogic Server 6.1 is the first e-commerce transaction platform to implement advanced J2EE 1.3 features. To comply with the rules governing J2EE, BEA Systems provides two separate downloads: one with J2EE 1.3 features enabled, and one that is limited to J2EE 1.2 features only. Both downloads offer the same container and differ only in the APIs that are available.
WebLogic Server 6.1 with J2EE 1.2 Plus Additional J2EE 1.3 Features
With this download, WebLogic Server defaults to running with J2EE 1.3 features enabled. These features include EJB 2.0, JSP 1.2, Servlet 2.3, and J2EE Connector Architecture 1.0. When you run WebLogic Server 6.1 with J2EE 1.3 features enabled, J2EE 1.2 applications are still fully supported. The J2EE 1.3 feature implementations use non-final versions of the appropriate API specifications. Therefore, application code developed for BEA WebLogic Server 6.1 that uses the new features of J2EE 1.3 may be incompatible with the J2EE 1.3 platform supported in future releases of BEA WebLogic Server.
WebLogic Server 6.1 with J2EE 1.2 Certification
With this download, WebLogic Server defaults to running with J2EE 1.3 features disabled and is fully compliant with the J2EE 1.2 specification and regulations.
Servlet Context Events
The following table lists the types of Servlet context events, the interface your event listener class must implement to respond to the event, and the methods invoked when the event occurs.
HTTP Session Events
The following table lists the types of HTTP session events, the interface your event listener class must implement to respond to the event, and the methods invoked when the event occurs.
Note: The Servlet 2.3 specification also contains the javax.servlet.http.HttpSessionBindingListener and the javax.servlet.http.HttpSessionActivationListener interfaces. These interfaces are implemented by objects that are stored as session attributes and do not require registration of an event listener in web.xml. For more information, see the Javadocs for these interfaces.
Configuring an Event Listener
To configure an event listener:
<listener> <listener-class>myApp.myContextListenerClass</listener-class> </listener>
<listener> <listener-class>myApp.mySessionAttributeListenerClass</listen er-class> </listener>
Writing a Listener Class
To write a listener class:
The following useful classes are passed into the listener methods in a listener class:
Templates for Listener Classes
The following examples provide some basic templates for listener classes.
Servlet Context Listener Example
package myApp; import javax.servlet.*;
public final class myContextListenerClass implements ServletContextListener { public void contextInitialized(ServletContextEvent event) { /* This method is called when the servlet context is initialized(when the Web Application is deployed). You can initialize servlet context related data here. */ }
public void contextDestroyed(ServletContextEvent event) { /* This method is invoked when the Servlet Context (the Web Application) is undeployed or WebLogic Server shuts down. */ } }
HTTP Session Attribute Listener Example
package myApp; import javax.servlet.*; public final class mySessionAttributeListenerClass implements HttpSessionAttributeListener { public void attributeAdded(HttpSessionBindingEvent sbe) { /* This method is called when an attribute is added to a session. */ }
public void attributeRemoved(HttpSessionBindingEvent sbe) { /* This method is called when an attribute is removed from a session. */ }
public void attributeReplaced(HttpSessionBindingEvent sbe) { /* This method is invoked when an attibute is replaced in a session. */ } }
Additional Resources
|
Copyright © 2001 BEA Systems, Inc. All rights reserved.
|