SPRINGMVC solutions for blocking static resources

Source: Internet
Author: User
problem BUG:

When using SPRINGMVC to deploy Web projects, we often have problems with 404 of resources not found when accessing static resources. Reason:

This is because Dispatcherservlet can intercept static resources and cause static resources to be inaccessible. Solution: scenario One, set the Defaultservlet in Web. XML, note that this configuration requires Dispatcherservlet interception before it can play an early intercept effect.

<servlet-mapping>
     <servlet-name>default</servlet-name>
     <url-pattern>*.css</ url-pattern>
</servlet-mapping>
<servlet-mapping>
     <servlet-name>default</ servlet-name>
     <url-pattern>*.gif</url-pattern>
</servlet-mapping>
< servlet-mapping>
     <servlet-name>default</servlet-name>
     <url-pattern>*.jpg</ url-pattern>
</servlet-mapping>
<servlet-mapping>
     <servlet-name>default </servlet-name>
     <url-pattern>*.js</url-pattern>
</servlet-mapping>
< servlet-mapping>
     <servlet-name>default</servlet-name>
     <url-pattern>*.png</ Url-pattern>
</servlet-mapping>

Where default is the name of Tomcat, if the other is the server can check the relevant default servlet name. Scenario Two, configure the resource in the SPRINGMVC configuration file

<mvc:resources mapping= "/images/**" location= "/images/"/>

Where location is the path to the static resource directory, mapping is mapped to resourcehttprequesthandler for processing. scenario Three, configuring the default Servlet processor for static resources in SPRINGMVC (this is the method I use frequently)

<mvc:default-servlet-handler/>

Reference article: http://lzy83925.iteye.com/blog/1186609

Related Article

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.