1. Activate Tomcat's defaultServlet to handle static files, web.xml configuration
<servlet-mapping><servlet-name>default</servlet-name><url-pattern>*.js</url-pattern></servlet-mapping>
a. Having said that, let’s talk about the configuration of url-pattern
<!--Three ways to write url-pattern--><!--Exact match: start with "/" and add the servlet name. -->/abc<!--Path Match: Start with "/", plus wildcard "*"-->/rsources/*<!--Extension Match: Start with wildcard "*", plus extension. -->*.action
2.Springmvc processing, spring-mvc.xml configuration
<mvc:resources location="/resources/" mapping="/resources/**"/>
3. The "/**" url will be registered in the urlMap of SimpleUrlHandlerMapping, and the access to static resources will be transferred from HandlerMapping to org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler and returned.
DefaultServletHttpRequestHandler is the default Servlet for each Servlet container.
<mvc:default-servlet-handler/>
Execution order of multiple HandlerMappings:
The order attribute value of DefaultAnnotationHandlerMapping is: 0
<mvc:resources/>The automatic registration of SimpleUrlHandlerMapping order property value is: 2147483646
<mvc:default-servlet-handler/> The order attribute value of the automatic registration of SimpleUrlHandlerMapping is: 2147483647
Spring will execute the order with a smaller order first.
The above is the processing of static files by springmvc and tomcat in the JavaWeb project introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!