} }

 Files   Prepare   Run   Troubleshooting   Related Topics 

 

About the Example

This class demonstrates the public ServletContextListener interface, which extends java.util.EventListener. Implementations of the ServletContextListener interface receive notifications about changes to the servlet context of the Web applications they are part of, essentially acting as lifecycle triggers.

In this example, when the examplesWebApp Web application is deployed and fully loaded, it executes the OpenBrowserServletContextListener class. The run target of this example results in the redeployment of the Web application.

You configure the ServletContext Listener class (in this case the OpenBrowserServletContextListener class) within the examplesWebApp Web application web.xml deployment descriptor as follows:

<listener> <listener-class>examples.webapp.lifecycle.OpenBrowserServletContextListener</listener-class> <listener>

The OpenBrowserServletContextListener class opens the client's default browser when servlet context is created for the examplesWebApp Web application. The browser shows the successful redeployment of examplesWebApp.

For more information on the ServletContextListener interface, see Initializing a Servlet.


 

Files Used in the Example

Directory Location:

MW_HOME/wlserver_10.3/samples/server/examples/webapp/lifecycle/

(where MW_HOME is the directory containing your WebLogic Server installation)

File

Click source files to view code.

Description

build.xml Ant build file that contains targets for building and running the example.
OpenBrowserServletContextListener.java Class that demonstrates the use of ServletContext listeners.

 

Prepare the Example

 

Prerequisites

Before working with this example:

  1. Install Oracle WebLogic Server, including the examples.
  2. Start the Examples server.
  3. Set up your environment.

 

Configuring WebLogic Server

  No special configuration is required for this example.

 

Building the Example

To build the example, follow these steps:

  1. Change to the SAMPLES_HOME\server\examples\src\examples\webapp\lifecycle\ directory, where SAMPLES_HOME refers to the main Oracle WebLogic Server examples directory, such as d:\Oracle\Middleware\wlserver_10.3\samples.
  2. Execute the following command from the shell where you set your environment:

    ant

The Ant command uses the build.xml file, located in the SAMPLES_HOME\server\examples\src\examples\webapp\lifecycle\ directory, to build the example.


 

Run the Example

To run the example, follow these steps:

  1. In your development shell, run the Web Application Caching example by using the following command from the example directory (SAMPLES_HOME\server\examples\src\examples\webapp\lifecycle\):

    prompt> ant run

The examplesWebAppServletContextListener configuration. A browser pops up to display http://localhost:port/index.jsp.

Where:

Note: To execute a Web-based example, you can manually open the browser to the appropriate URL or you can use the build.xml run target by entering ant run at the command prompt. Oracle recommends using the latter method to run the example.

The following output is displayed:

	$ ant
    Buildfile: build.xml

    run:
	redeploy.webapp:
    redeploy.webapp:
    [wldeploy] weblogic.Deployer -noexit -name examplesWebApp -user weblogic -password ******** -redeploy
    [wldeploy] Task 5 initiated: [Deployer:149026]redeploy application examplesWebApp on examplesServer.
    [wldeploy] Task 5 completed: [Deployer:149026]redeploy application examplesWebApp on examplesServer.
    [wldeploy] Deployment completed on Server examplesServer
    [wldeploy]
    BUILD SUCCESSFUL
	Total time: 7 seconds

 

Troubleshooting

There are no troubleshooting topics for this example.


 

Related Topics

(Internet connection required.)