FAQ
History
PreviousHomeNext Search
Feedback
Divider

Configuring Web Modules

Web applications are configured via elements contained in the Web application deployment descriptor. The IDE generates the descriptor when you create a Web module and adds elements when you create Web components and associated classes. You can modify the elements via the property sheets associated with the descriptor.

The following sections give a brief introduction to the Web application features you will usually want to configure. A number of security parameters can be specified; these are covered in a future release of the tutorial. For a complete listing and description of the features, see the Java Servlet specification.

In the following sections, some examples demonstrate procedures for configuring the Hello, World application. If Hello, World does not use a specific configuration feature, the section gives uses other examples for illustrating the deployment descriptor element and describes generic procedures for specifying the feature using the IDE. Extended examples that demonstrate how to use the IDE are in The Example Servlets and The Example JSP Pages.

Request Mapping

When a request is received by the Sun application server 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 application and a Web component. A URL path contains the context path and a servlet path

http://<host>:80/context_path/servlet_path 

A context path identifies a Web application. For example, to view the context of the Hello1 application:

  1. Select the WEB-INF node of the Hello1 Web module.
  2. Note that the Context Root property value is set to /hello1.

The servlet path identifies the Web component that should handle a request. The servlet 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 a servlet path that ends with *.jsp, you do not have to specify a servlet path for a JSP page unless you wish to refer to the page by a name other than its file name. In the Hello2 example, the greeting page has a servlet path, but response.jsp is called by name.

To view the servlet path for the Hello2 application:

  1. In the IDE, mount the filesystem
    <INSTALL>/j2eetutorial/examples/web/hello2.
  2. Expand the nodes hello2.
  3. Select the greeting JSP page.
  4. Select the Deployment Entries property and open the property editor.
  5. Notice that the JSP page /greeting.jsp has the servlet name greeting and is mapped to the URL /greeting.

Initialization Parameters

The Web components in a Web module share an object that represents their application context (see Accessing the Web Context). You can pass initialization parameters to the context or Web component.

To add a context parameter in the IDE:

  1. Mount the Web module as a filesystem and expand it.
  2. Expand the WEB-INF node.
  3. Select the web.xml file.
  4. Select the Deployment tab in the property editor.
  5. Select the Context Parameters property and open the property editor.
  6. Click Add.
  7. Type the parameter name and value.
  8. Click OK twice.

For an example context parameter, page mapping, see The Example JSP Pages.

To add a Web component initialization parameter in the IDE:

  1. Mount the Web module as a filesystem and expand it.
  2. Select the Web component.
  3. Select the Deployment Entries property and open the property editor.
  4. Click Edit.
  5. Under the Init Parameters table, click Add.
  6. Type the parameter name and value.
  7. Click OK twice.

Error Mappings

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, you must specify the Error Pages property for the Web deployment descriptor. To add an error mapping in the IDE:

  1. Mount the Web module as a filesystem.
  2. Expand the WEB-INF node.
  3. Select the web.xml file.
  4. Select the Deployment tab in the property editor.
  5. Select the Error Pages property and open the property editor.
  6. Click Add.
  7. Add an HTTP Error Code (see HTTP Responses) or Java Exception Type.
  8. Enter the name of a resource to be invoked when the status code or exception is returned in the Error Page Field. The name should have a leading forward slash /.

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


For an example error page mapping, see The Example Servlets.

References to Environment Entries, Resource Environment Entries, or Resources

If your Web components reference environment entries, resource environment entries, or resources such as databases, you must declare the references with in the Web application deployment descriptor. To add a reference in the IDE:

  1. Mount the Web module as a filesystem.
  2. Expand the WEB-INF node.
  3. Select the web.xml file.
  4. In the properties sheet, select the References tab.
  5. Click the Resource References Property and open the property editor.
  6. Click Add.
  7. Type a JNDI name for the resource.
  8. Choose the type of the resource.
  9. Choose whether the container or the application performs authentication when the resource is accessed.
  10. Choose whether the resource can be shared by more than one Web application.

For an example resource reference, see Configuring the Web Application to Reference a Data Source with JNDI.

Divider
FAQ
History
PreviousHomeNext Search
Feedback
Divider

All of the material in The J2EE Tutorial for the Sun ONE Platform is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.