All Examples

Web Application (WAR) examples

This directory contains an very simple example Web Application for the WebLogic Server. Web Application are defined as part of the Servlet 2.2 specification.

how to setup the cookie Web Application example

To setup and build the cookie Web Applicaiton example in this directory, follow these steps.

  1. Register the Web Application in the file using the property:
    where cookie is part of the request URL that identifies the servlet context for this Web Application. HTTP requests made to this Web Application will follow the pattern:
    And, webapp_dir is the full directory path to the root directory of the Web Application. The root directory of each Web Application is that Web Application's document root. The cookie Web Application example root directory is in this directory.

    To register the 'cookie' Web Application example, add the following line to your file. Here we presume that you have installed WebLogic in the root directory /weblogic on your system for simplicity. You should alter the property appropriately.

    Here, we set the context path to "cookie". Note that the Web Application root directory and the context path need not have the same name.

  2. Next, compile the CookieCounter servlet in the Web Application. Server-side classes and servlets used by the Web Application should be located under the WEB-INF/classes directory. This is a different approach to the location used for servlets deployed on WebLogic prior to introduction of the Web Application. We refer to the older-style deployment as being deployed in the default servlet context.

    Open a new command shell, and set up your development environment, as described in the document Setting your development environment. Change to the WEB-INF directory under the cookie Web Application root directorty.

    If necessary, create a classes directory using:

     $  mkdir classes

    Compile the CookieCounter servlet using the following command line:

     $  javac -d classes

  3. Start (or restart) the WebLogic Server.

  4. Open a web browser and request the URL:

    The Web Application has been configured to serve the welcome page "hello.html" when the root directory is requested. You can see this configured in the WEB-INF/web.xml file shown below:


    The CookieCounter servlet has been mapped to the URI path "monster". You can access it by requesting the URL:

    or clicking on the link in the welcome page.

    The Web Application has been configured to deliver an error JSP file if you attempt to request a bogus resource within this Web Application's servlet context. Try requesting the URL:

    The default error page has been configured to handle HTTP 404 errors. You can configure other pages to handle other HTTP error codes.

how to create a WAR file

A WAR file is an archived web application. You can deploy a Web Application on the WebLogic Server in its archived format. This is useful for deploying an entire Web Application on a server other than the development environment host, a remote host, or for deploying to multiple servers in a cluster.

To create a WAR file open a command shell and change to the directory that contains the root directory of your Web Application. Set up your development environment as described in Setting your development environment, to ensure that you have a JDK in your environment path. Now, archive the entire Web Application using the JAR tool on the command line after the pattern:

 $  jar cvf myWar.war myApp
where myWar.war is the name given to the newly created WAR file, and myApp is the root directory name of your Web Application.

Now move the .war file to the host server. We suggest that you place it in the myserver diectory in the WebLogic installation directory, but you can place it anywhere on a file system accessible by the host server.

Register the WAR file in the file using the same property as for an un-archived Web Application:

where contextName is the servlet context path that prepends request URIs to this Web Application. To archive and deploy the cookie example, change to the examples/webapp directory and create a WAR file using:
 $  jar cvf cookieWar.war cookie
Move the cookieWar.war file to the myserver directory and register the WAR using following property in the file:
Now start (or restart) the WebLogic Server and request the URL http://localhost:7001/cookie

there's more

Read more about Web Applciations in the Developers Guide, Writing a Web Application.

Other Developers Guides that describe the functionality used by this example are:

Copyright © 2000 BEA Systems, Inc. All rights reserved.

Last updated 01/10/2000