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, 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.
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.