Java Web project springmvc, and tomcat processing of static files, javawebspringmvc
1. Activate Tomcat's defaultServlet to process static files, web. xml configuration
<servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> </servlet-mapping>
A. Let's talk about the url-pattern configuration here.
<! -- Three methods of url-pattern --> <! -- Exact match: Start with "/" and add the servlet name. -->/Abc <! -- Path match: starts with "/" and adds the wildcard "*" -->/rsources/* <! -- Extension match: starts with the wildcard "*" and adds the extension. --> *. Action
2. springmvc processing, spring-mvc.xml Configuration
<mvc:resources location="/resources/" mapping="/resources/**"/>
3. the "/**" url is registered to the urlMap of SimpleUrlHandlerMapping, and the access to static resources is transferred from HandlerMapping to org. springframework. web. servlet. resource. defaultServletHttpRequestHandler process and return.
DefaultServletHttpRequestHandler is the default Servlet of each Servlet container.
<mvc:default-servlet-handler/>
Execution sequence of HandlerMapping:
The attribute value of order DefaultAnnotationHandlerMapping is: 0.
<Mvc: resources/> the automatically registered order attribute value of SimpleUrlHandlerMapping is: 2147483646.
<Mvc: default-servlet-handler/> the order attribute value of automatically registered SimpleUrlHandlerMapping is: 2147483647.
Spring will first execute a small order.
Summary: I personally think the first one is better. If no static file is used for cdn, it is better to use the default servlet for better processing, so that it will not be processed by the interceptor.