} }
Files Prepare Run Troubleshooting Related Topics
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.
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. |
Before working with this example:
No special configuration is required for this example.
To build the example, follow these steps:
The Ant command uses the build.xml file, located in the SAMPLES_HOME\server\examples\src\examples\webapp\lifecycle\ directory, to build the example.
To run the example, follow these steps:
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
There are no troubleshooting topics for this example.
(Internet connection required.)