The J2EETM Tutorial
Home
TOC
PREV TOC NEXT Search
Feedback

Configuring Web Components

The following sections describe the web component configuration parameters that you will usually want to specify. Configuration parameters are specified at three levels: application, WAR, and component. A number of security parameters can be applied at the WAR and component levels. For information on security parameters, see Security.

Application-Level Configuration

Context Root

A context root is a path that gets mapped to the document root of a J2EE application. If the entry URL of an application is the same as the base of the web server's URL namespace (for example http://<host>:8000), the context root is an empty string. If your application's context root is catalog, then a request URL such as http://<host>:8000/catalog/index.html will retrieve the file index.html from the application's document root.

To specify the context root for the hello1 application in deploytool:

  1. Select the hello1 application.
  2. Select the Web Context tab and enter hello1 in the Context Root field.

WAR-Level Configuration

The following sections give generic procedures for specifying WAR-level configuration information. For some specific examples, see The Example Servlets.

Context Parameters

The web components in a WAR share an object that represents their web context (see Accessing the Web Context). You can specify initialization parameters that are passed to the context as follows:

  1. Select the WAR.
  2. Select the Context Parameters tab.
  3. Click Add.

References to Environment Entries, Enterprise Beans, Resource Environment Entries, or Resources

If your web components reference environment entries, enterprise beans, resource environment entries, or resources such as databases, you must declare the references as follows:

  1. Select the WAR.
  2. Select the Environment, Enterprise Bean Ref's, Resource Env. Ref's or Resource Ref's tab.
  3. Click Add in the panel to add a new reference.

Event Listeners

To add an event listener class (described in Monitoring Servlet Life Cycle Events).

  1. Select the WAR.
  2. Select the Event Listeners tab.
  3. Click Add.
  4. Select the listener class from the new field in the Event Listener Classes panel.

Error Mapping

You can specify a mapping between the status code returned in an HTTP response or a Java programming language exception returned by any web component and another web component or resource (see Handling Errors). To set up the mapping:

  1. Select the WAR.
  2. Select the File Ref's tab.
  3. Click Add in the Error Mapping panel.
  4. Enter the HTTP status code (see HTTP Responses) or fully-qualified class name of an exception in the Error/Exception field.
  5. Enter the name of a resource to be invoked when the status code or exception is returned. The name should have a leading '/'.

Note: You can also define error pages for a JSP page contained in a WAR. If error pages are defined for both the WAR and a JSP page, the JSP page's error page takes precedence.

Filter Mapping

A web container uses filter mapping declarations to decide which filters to apply to a request, and in what order (see Filtering Requests and Responses). The container matches the request URI to a servlet as described in Specifying an Alias Path. To determine which filters to apply, it matches filter mapping declarations by servlet name or URL pattern. The order in which filters are invoked is the order in which filter mapping declarations that match a request URI for a servlet appear in the filter mapping list.

You specify a filter mapping in the deploytool as follows:

  1. Select the WAR.
  2. Select the Filter Mapping tab.
  3. Add a filter
    1. Click Edit Filter List.
    2. Click Add.
    3. Select the filter class.
    4. Enter a filter name.
    5. Add any filter initialization parameters.
    6. Click OK.
  4. Map the filter
    1. Click Add.
    2. Select the filter name.
    3. Select the target type. A filter can be mapped to a specific servlet or to all servlets that match a given URL pattern.
    4. Specify the target. If the target is a servlet, select the servlet from the drop-down list. If the target is a URL pattern, enter the pattern.

Component-Level Configuration

Initialization Parameters

You can specify parameters that are passed to the web component when it is initialized as follows:

  1. Select the web component.
  2. Select the Parameters tab.
  3. Click Add to add a new parameter and value.

Specifying an Alias Path

When a request is received by a web container it must determine which web component should handle the request. It does so by mapping the URL path contained in the request to a web component. A URL path contains the context root (described in Context Root) and an alias path:

http://<host>:8000/context root/alias path 

Therefore, before your web component can be accessed, the web container must have least one alias path for the component. The alias path must start with a '/' and end with a string or a wildcard expression with an extension (*.jsp for example). Web containers automatically map an alias path that ends with *.jsp to a servlet that transforms and compiles JSP pages, unless an application specifies otherwise.

You set up the mappings for the servlet version of the Hello application using the web component inspector as follows:

  1. Select the greeting web component in the hello1 WAR.
  2. Select the Aliases tab.
  3. Click Add to add a new mapping.
  4. Type /greeting in the aliases list.
  5. Select the response web component in the hello1 WAR.
  6. Click Add.
  7. Type /response in the aliases list.
Home
TOC
PREV TOC NEXT Search
Feedback