Java Web project springmvc, and tomcat processing of static files, javawebspringmvc

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.