The J2EETM Tutorial
Home
TOC
Index
PREV TOP NEXT Search
Feedback

Configuring Web Clients

The following sections describe the Web client 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 these security parameters, see Web-Tier Security.

Application-Level Configuration

Context Root

A context root is a name that gets mapped to the document root of a Web client. If your client's context root is catalog, then the request URL

http://<host>:8000/catalog/index.html 
 

will retrieve the file index.html from the document root.

To specify the context root for Hello1App in deploytool,

  1. Select Hello1App.
  2. Select the Web Context tab
  3. 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). To specify initialization parameters that are passed to the context,

  1. Select the WAR.
  2. Select the Context 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 Refs, Resource Env. Refs or Resource Refs tab.
  3. Click Add in the pane to add a new reference.

Event Listeners

To add an event listener class (described in Handling 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 pane.

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 a Web resource (see Handling Errors). To set up the mapping,

  1. Select the WAR.
  2. Select the File Refs tab.
  3. Click Add in the Error Mapping pane.
  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 forward slash /.

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 Uniform Resource Identifier (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 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

To specify parameters that are passed to the Web component when it is initialized,

  1. Select the Web component.
  2. Select the Init. 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 the section Context Root) and an alias path:

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

Before a servlet can be accessed, the Web container must have at 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). Since Web containers automatically map an alias path that ends with *.jsp, you do not have to specify an alias path for a JSP page unless you wish to refer to the page by a name other than its file name. In the example discussed in the section Updating Web Clients, the page greeting.jsp has an alias, /greeting, but the page response.jsp is referenced by its file name within greeting.jsp.

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

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