Problems with servlet default index.jsp and /

I set servlet mapping

<servlet>
      <servlet-name>Site</servlet-name>
      <servlet-class>com.demo.controller.App</servlet-class>
  </servlet>

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

there is also an index.jsp in the webapp directory

< hr >

so that when I visit http://localhost:8080/, I will still go index.jsp
without triggering the doGet method of my default App controller
unless I casually write a directory such as http://localhost:8080/a/ will trigger

.

Why is this?

Mar.08,2022

I already know what's going on.
because I have index.jsp, in the web root directory and then I access the default path, tomcat will map your path to xxx/index.jsp, and then exactly match the last controller called JspServlet to deal with it according to the Servlet matching rule. If I change index.jsp to index.html, I will handle it with my servlet

Menu