Class DefaultServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.apache.catalina.servlets.DefaultServlet
All Implemented Interfaces:
Servlet, ServletConfig, Serializable
Direct Known Subclasses:
WebdavServlet

public class DefaultServlet extends HttpServlet

The default resource-serving servlet for most web applications, used to serve static resources such as HTML pages and images.

This servlet is intended to be mapped to / e.g.:

   <servlet-mapping>
       <servlet-name>default</servlet-name>
       <url-pattern>/</url-pattern>
   </servlet-mapping>
 

It can be mapped to sub-paths, however in all cases resources are served from the web application resource root using the full path from the root of the web application context.
e.g. given a web application structure:

 /context
   /images
     tomcat2.jpg
   /static
     /images
       tomcat.jpg
 

... and a servlet mapping that maps only /static/* to the default servlet:

   <servlet-mapping>
       <servlet-name>default</servlet-name>
       <url-pattern>/static/*</url-pattern>
   </servlet-mapping>
 

Then a request to /context/static/images/tomcat.jpg will succeed while a request to /context/images/tomcat2.jpg will fail.

Author:
Craig R. McClanahan, Remy Maucherat
See Also: