Spring requests a static resource file

Source: Internet
Author: User

Using restful style writing in the SPRINGMVC project, you need to configure full interception to Web. Xml.


However, static resources such as IMAGE,JS,CSS do not want to intercept the project. There are three ways to configure it:

I. Web. XML filtering


But this needs to be configured for each type, cumbersome and easy to miss. To be straightforward, spring provides two ways to handle it. You need to include the MVC tag in the spring configuration file

Xmlns:mvc= "Http://www.springframework.org/schema/mvc"
Xsi:schemalocation= "
Http://www.springframework.org/schema/mvc/spring-mvc.xsd "

Second, the use of mvc:resources.

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

Third, use the default servlet to respond to static files <mvc:default-servlet-handler/>

Spring requests a static resource file

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.