|
Home TOC |
|
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 iscatalog, then a request URL such ashttp://<host>:8000/catalog/index.htmlwill retrieve the fileindex.htmlfrom the application's document root.To specify the context root for the
Hello1Appapplication indeploytool,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,
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:
- Select the WAR.
- Select the Environment, Enterprise Bean Refs, Resource Env. Refs or Resource Refs tab.
- Click Add in the panel to add a new reference.
Event Listeners
To add an event listener class (described in Handling Servlet Life Cycle Events),
- Select the WAR.
- Select the Event Listeners tab.
- Click Add.
- 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,
- Select the WAR.
- Select the File Refs tab.
- Click Add in the Error Mapping panel.
- Enter the HTTP status code (see HTTP Responses) or fully-qualified class name of an exception in the Error/Exception field.
- 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
deploytoolas follows:
- Select the WAR.
- Select the Filter Mapping tab.
- Add a filter
- Click Edit Filter List.
- Click Add.
- Select the filter class.
- Enter a filter name.
- Add any filter initialization parameters.
- Click OK.
- Map the filter
Component-Level Configuration
Initialization Parameters
To specify parameters that are passed to the web component when it is initialized,
- Select the web component.
- Select the Init. Parameters tab.
- 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 pathBefore a servlet 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 (*.jspfor 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 Updating Web Components, the pagegreeting.jsphas an alias,/greeting, but the pageresponse.jspis referenced by its file name withingreeting.jsp.You set up the mappings for the servlet version of the Hello application using the web component inspector as follows:
|
Home TOC |
|
Search
Feedback |