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.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo are registered trademarks of Rogue Wave Software, and HydraExpress is a trademark of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.