前端控制器DispatcherServlet的中/和/*的深入分析
博客的内容概述
问题2:
但是到底是为什么呢?
The /* on a servlet overrides all other servlets, including all
servlets provided by the servletcontainer such as the default servlet
and the JSP servlet. Whatever request you fire, it will end up in that
servlet. This is thus a bad URL pattern for servlets. Usually, you’d
like to use /* on a Filter only. It is able to let the request
continue to any of the servlets listening on a more specific URL
pattern by calling FilterChain#doFilter().
he / doesn’t override any other servlet. It only replaces the
servletcontainer’s builtin default servlet for all requests which
doesn’t match any other registered servlet. This is normally only
invoked on static resources (CSS/JS/image/etc) and directory listings.
The servletcontainer’s builtin default servlet is also capable of
dealing with HTTP cache requests, media (audio/video) streaming and
file download resumes. Usually, you don’t want to override the default
servlet as you would otherwise have to take care of all its tasks,
which is not exactly trivial (JSF utility library OmniFaces has an
open source example). This is thus also a bad URL pattern for
servlets. As to why JSP pages doesn’t hit this servlet, it’s because
the servletcontainer’s builtin JSP servlet will be invoked, which is
already by default mapped on the more specific URL pattern *.jsp.
希望能帮到你!!!