Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
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
andservlet-mapping
. Allservlet
elements must appear before anyservlet-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 ashttp://hostname:8000/bookstore/catalog
will send the request to the servlet namedcatalog
within thebookstore
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 for the Duke's Bookstore example.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |