Springmvc How to access static files, such as Jpg,js,css

Source: Internet
Author: User

How your Dispatcherservlet intercepts "*.do" such as a URL with a suffix, there is no problem of access to static resources.
If your dispatcherservlet intercepts "/", in order to implement the rest style, all requests are intercepted, and access to static files such as *.js,*.jpg is intercepted.

First, I do the project is to use HTML to jump, due to the code cleanliness, try to use pure Ajax and HTML as interactive display page, with SPRINGMVC do the background processing program.

Scenario One : Activate Tomcat's defaultservlet to handle static files

Need to be configured in Web. xml

<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>*.css</ Url-pattern>      </servlet-mapping>

Scenario Two : only the. do file is blocked

<servlet-mapping><servlet-name>mvc-dispatcher</servlet-name><url-pattern>/.do</ Url-pattern></servlet-mapping>

Scenario three : Use Mvc:resources. Location refers to the path under Webroot. Mapping refers to the mappings to be processed.

<mvc:resources location= "/pages/"  

Note Header file

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:context= "http://www.springframework.org/ Schema/context "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xmlns:mvc=" http://www.springframework.org/ Schema/mvc "  xsi:schemalocation="        Http://www.springframework.org/schema/beans/             http Www.springframework.org/schema/beans/spring-beans-3.0.xsd        Http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-3.0.xsd        http://www.springframework.org/ SCHEMA/MVC          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd ">

Springmvc How to access static files, such as Jpg,js,css

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.