SPRINGMVC Interceptor (interceptors) to the style (CSS), JavaScript (JS), picture (images) Link interception

Source: Internet
Author: User

Because the Web. XML is configured with the

<servlet-mapping><servlet-name>appservlet</servlet-name><url-pattern>/</url-pattern ></servlet-mapping>

Causes all connections to be dispatcherservlet, so static resources such as css,js,images are filtered to make the page impossible to render successfully.

However, in the main configuration file, we can add <mvc:resources location= "", so that the static resources will not go through the Dispatcherservlet, you can successfully render the page.

<!--requests to handle static resources--><mvc:resources location= "/web-inf/views/css/" mapping= "/css/**"/><mvc:resources location= "/web-inf/views/js/" mapping= "/js/**"/><mvc:resources location= "/images/" mapping= "/images/**"/ >

However, the SPRINGMVC also has a mechanism for interceptors (if you don't use interceptors, then there's no problem), but it also intercepts the request link to our static resources.

By the output I saw in the interceptor, I actually intercepted the request link to the static resource, so my page would have the following error:

Resource interpreted as Stylesheet but transferred with MIME type text/html:

I still didn't find any other reason, so I filtered the static resource link on the interceptor, and then didn't produce the above problem.

While the other pages do not produce the above problem, but the static resources to filter the link, should not have any impact.

<mvc:interceptors><mvc:interceptor><mvc:mapping path= "/**"/> <!--because I've blocked all the links, the links to the static resources have been blocked. --><mvc:exclude-mapping path= "/js/**"/><mvc:exclude-mapping path= "/css/**"/><MVC: Exclude-mapping path= "/images/**"/><bean class= "Com.databasegroup.interceptor.AuthInterceptor" ></ Bean></mvc:interceptor></mvc:interceptors>

  

  

SPRINGMVC Interceptor (interceptors) to the style (CSS), JavaScript (JS), picture (images) Link interception

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.