How do I override Tomcat's own default servlet (default) with custom servlet?

scenario: customize a MyDefaultServlet with urlPatterns = "/"; when processing a request, only request.getRequestDispatcher ("/ test.html") .forward (request, response) is used;
test.html exists. The purpose of the code is to understand the default servlet.
question:
1. In the container at this time, both default (the default servlet of the container) and MyDefaultServlet servlet are mapped to "/". Why is this possible?
2. Java.lang.StackOverflowError is thrown when the code is executed, which is easy to understand. The question is how to prevent MyDefaultServlet from dealing with static resources such as html? My solution is to use context.getNamedDispatcher ("default") .forward (request,response); leave it to the container default servlet (default) to handle, and the test is feasible. Is there a more concise way? In web.xml

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

after testing: both default and MyDefaultServlet will work. There seems to be an order. Give it to default first. If default can handle it, it won"t give it to MyDefaultServlet. If default can"t handle it, give it to MyDefaultServlet. However, when you comment out the < servlet-mapping > of default in web.xml, only MyDefaultServlet will work, and it seems that the container default servlet (default) needs to be "activated."
3. The above tests are difficult to get a consistent understanding, how to understand the mechanism of the default servlet (default)?

thank you!

Jun.06,2022
Menu