If the mapping path for a servlet is a forward slash/, the servlet represents the default servlet for the current web App
When the servlet server receives an access request, the default servlet processing request is invoked if the URL of the matching <servlet-mapping> element is not found in the Web. xml file
That is, the default servlet is used to process access requests that are not processed by other Servlets
Sample code
<servlet>
<description></description>
<display-name>testservlet01</ display-name>
<servlet-name>TestServlet01</servlet-name>
<servlet-class> cn.itcast.chapter04.servlet.testservlet01</servlet-class>
</servlet>
<!--mapping default servlet-- >
<servlet-mapping>
<servlet-name>TestServlet01</servlet-name>
< Url-pattern>/</url-pattern>
</servlet-mapping>
Launch Tomcat, enter the URL in the browser
Http://localhost:8080/chapter04/abcd
The results are shown below
As you can see, when the URL path is freely entered
can still access TestServlet01
Attention
The Web. xml file under the Tomcat installation directory
A default servlet is also configured
Configured as follows
<servlet>
<servlet-name>default</servlet-name>
<servlet-class> Org.apache.catalina.servlets.defaultservlet</servlet-class>
<load-on-startup>1</ load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>default</ servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Org.apache.catalina.servlets.DefaultServlet, which is set as the default servlet
All Web apps work on the Tomcat server, and when a web app doesn't have a default servlet, it calls the default servlet on Tomcat
When a client accesses a static HTML file in a Tomcat server, Defaultservlet will determine if the HTML file exists
If present, the data is sent back to the client in the form of a stream
Otherwise, a 404 error will be reported