Servlet Development Guide : PART I Introduction : Chapter 3 Introduction to Servlet Programming : Adding the Servlet to the web.xml file
Adding the Servlet to the web.xml file
Each servlet must appear in a web.xml file within a context directory. To add a servlet to an existing context, add a servlet and servlet-mapping element to the context. The sample below shows a complete web.xml file for the HelloWorldExample servlet:
 
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>servletexample.createHelloWorldExample
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorldExample/*</url-pattern>
</servlet-mapping>
</web-app>
The deployment descriptor above creates an instance of the HelloWorldExample servlet and names that instance HelloWorld. Because the servlet is located in the examples context, i.e. at <installdir>\apps\servlets\examples, the url-pattern element maps the servlet to /examples/HelloWorldExample/. That is, the container forwards all requests that begin with /examples/HelloWorldExample/ to the HelloWorld instance. This servlet configuration is identical to the configuration for HelloWorldExample in the web.xml file for the examples context.
Chapter 4 explains the context web.xml file and describes how to deploy and configure servlets, filters, and listeners.