The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Servlets
Lesson: Running Servlets

Configuring Tomcat Servlets

You configure servlet application behavior by specifying elements in a text file called a Web application deployment descriptor. This file must be named web.xml and placed in a specific location when you install an application in Tomcat. The types of information that you specify and the format of the Web application deployment descriptor are described in the Java Servlet specification (versions 2.2 and 2.3).

The Duke's Bookstore application uses two Web application deployment descriptor elements: servlet and servlet-mapping. All servlet elements must appear before any servlet-mapping elements.
 

The Servlet Element

The servlet element establishes a mapping between a servlet name and the fully-qualifed name of the servlet class:

   <servlet>
      <servlet-name>catalog</servlet-name>
      <servlet-class>CatalogServlet</servlet-class>
   </servlet>

 

The Servlet Mapping Element

When a request is received by Tomcat it must determine which servlet should handle it. You designate that certain paths (called aliases) map to a specific servlet with the servlet-mapping element. Alias paths appears after the context root in an HTTP request URL.

A context root is a path that gets mapped to the document root of the servlet application. If your application's context root is /bookstore, then a request URL such as http://hostname:8000/bookstore/catalog will send the request to the servlet named catalog within the bookstore context. You set the context root and document root for an application when you configure the Tomcat server.

   <servlet-mapping>
      <servlet-name>catalog</servlet-name>
      <url-pattern>/catalog</url-pattern>
   </servlet-mapping>

 

The Web Application Deployment Descriptor

Here is the Web application deployment descriptor(outside of the tutorial) for the Duke's Bookstore example.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.