How do I designate a servlet to serve as a default servlet for a given webapp under Servlet 2.2 API?

Avi Kak

Through the servlet-mapping element of the webapp deployment descriptor file web.xml. The url-pattern sub-element of the servlet-mapping element must be set to '/'.

If made available, a default servlet is executed by the server whenever the client browser points to the URL

or to the URL

For example, for a webapp named test-suite, the deployment descriptor shown below permits my server to execute the DefaultHelloServlet for the following URLs:



for any pathname substituted for NonExistentServlet provided it does not begin with /servlet/.

Here is the deployment descriptor (web.xml) for this example that sits in the WEB-INF directory of my test-suite webapp:

<?xml version="1.0"?>




See also Alex Chaffee's Servlet FAQ entry dealing with servlet aliasing.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact