Scenario one, the interceptor adds no filtering for static resources (involving Spring-mvc.xml)
<mvc:resources location= "/" mapping= "/**/*.js"/> <mvc:resources location= "/" mapping= "/**/*.css"/> < Mvc:resources location= "/assets/" mapping= "/assets/**/*"/> <mvc:resources location= "/images/" mapping= "/ images/* "cache-period=" 360000 "/><mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**/* "/> <mvc:exclude-mapping path="/**/fonts/* "/> <mvc:exclude-mapping path="/**/*.css "/> <mvc:exclude-mapping path= "/**/*.js"/> <mvc:exclude-mapping path= "/**/*.png"/> <mvc:exclude-m Apping path= "/**/*.gif"/> <mvc:exclude-mapping path= "/**/*.jpg"/> <mvc:exclude-mapping path= "/** /*.jpeg "/> <mvc:exclude-mapping path="/**/*login* "/> <mvc:exclude-mapping path="/**/*login* "/> ; <bean class= "Com.luwei.console.mg.interceptor.VisitInterceptor" ></bean> </mvc:interceptor>< /mvc:interceptors>
Scenario two, using the default static resource handling servlet to handle static resources (involving Spring-mvc.xml, Web. xml)
To enable the default servlet in Spring-mvc.xml
1 <mvc:default-servlet-handler/>
Increase the processing of static resources in Web. xml
<servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</ url-pattern> <url-pattern>*.css</url-pattern> <url-pattern>/assets/* "</ url-pattern> <url-pattern>/images/*</url-pattern> </servlet-mapping>
* But the current setting must be in front of spring's dispatcher
Scenario three, modify spring's global interception setting to *.do interception (involving web. xml)
<servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> < Param-name>contextconfiglocation</param-name> <param-value>classpath:spring-mvc.xml</ param-value> </init-param> <load-on-startup>1</load-on-startup> < Async-supported>true</async-supported></servlet><servlet-mapping> <servlet-name >SpringMVC</servlet-name> <url-pattern>*.action</url-pattern></servlet-mapping>
With this setting, spring will only process requests that end with '. Do ' and no longer maintain static resources
For the pros and cons of these three scenarios:
The first scenario configuration is more bloated, multiple interceptors increase the number of file lines, not recommended;
The second scenario uses the default servlet for resource file access, spring intercepts all requests, and then sevlet the resource files to the default, with few performance losses;
The third option, spring, is to deal with access at the end of '. Action ', which is more performance-efficient, but must end with '. Action ' on the re-access path, and the URL is less elegant;
In summary, it is recommended to use the second and third scenarios
recommended for use after SpringMVC3.0:
<mvc:resources location= "/web-inf/html/" mapping= "/**/*.html"/><mvc:resources location= "/WEB-INF/html/" mapping= "/**/*.ico"/><mvc:resources location= "/web-inf/html/" mapping= "/**/*.js"/><mvc:resources location= "/web-inf/html/" mapping= "/**/*.css"/><mvc:resources location= "/web-inf/html/" mapping= "/**/*.png" /><mvc:resources location= "/web-inf/html/" mapping= "/**/*.gif"/><mvc:resources location= "/WEB-INF/ html/"mapping="/**/*.jpg "/><mvc:resources location="/web-inf/html/"mapping="/**/*.ttf "/><MVC: Resources location= "/web-inf/html/" mapping= "/**/*.woff"/><mvc:resources location= "/web-inf/html/" mapping= " /**/*.woff2 "/>
Common problems in JSP to prevent SPRINGMVC interceptors from blocking the solution of static resource files such as JS