SPRINGMVC static resource processing [GO]

Source: Internet
Author: User

Springmvc Configure Dispatchservlet to filter all requests:

<servlet>         <Servlet-name>Mvc-dispatcher</Servlet-name>          <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>          <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping>          <Servlet-name>Mvc-dispatcher</Servlet-name>          <Url-pattern>/</Url-pattern> </servlet-mapping>

will cause all static resources such as: JS, CSS, PNG, GIF and other pages interception, this is not what we expected.

Workaround:

1. Take advantage of Spring's features:

<mapping= "/skins/**"  location= "/skins/"/>

For access to files under the mapping path, direct to location.

Problem: Introducing static resources requires knowing that content Path cannot be introduced in content Path,css

2. Use the default servlet to filter static resources without using Dispatchservlet

Configure in Web. xml

< servlet-mapping >             < Servlet-name >default</servlet-name>             <Url-pattern  >/skins/*</url-pattern></  Servlet-mapping>

For resources that have skins in access routes, use the default servlet

3. Use the default servlet to filter specific file name extensions

Configure in Web. xml

<servlet-mapping> <Servlet-name>Default</Servlet-name> <Url-pattern>*.png</Url-pattern> <Url-pattern>*.js</Url-pattern> <Url-pattern>*.css</Url-pattern> </servlet-mapping>

Similar to Method 2

We can choose the most suitable method according to their actual situation.

Springmvc static resource processing [go]

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.