1 <mvc:resources location="/" mapping="/**/*.js"/> 2 <mvc:resources location="/" mapping="/**/*.css"/> 3 <mvc:resources location="/assets/" mapping="/assets/**/*"/> 4 <mvc:resources location="/images/" mapping="/images/*" cache-period="360000"/> 5 6 <mvc:interceptors> 7 <mvc:interceptor> 8 <mvc:mapping path="/**/*"/> 9 <mvc:exclude-mapping path="/**/fonts/*"/> 10 <mvc:exclude-mapping path="/**/*.css"/> 11 <mvc:exclude-mapping path="/**/*.js"/> 12 <mvc:exclude-mapping path="/**/*.png"/> 13 <mvc:exclude-mapping path="/**/*.gif"/> 14 <mvc:exclude-mapping path="/**/*.jpg"/> 15 <mvc:exclude-mapping path="/**/*.jpeg"/> 16 <mvc:exclude-mapping path="/**/*login*"/> 17 <mvc:exclude-mapping path="/**/*Login*"/> 18 <bean class="com.luwei.console.mg.interceptor.VisitInterceptor"></bean> 19 </mvc:interceptor> 20 </mvc:interceptors>
方案二、使用默认的静态资源处理Servlet处理静态资源(涉及spring-mvc.xml, web.xml)
在spring-mvc.xml中启用默认Servlet
1 <mvc:default-servlet-handler/>
在web.xml中增加对静态资源的处理
1 <servlet-mapping> 2 <servlet-name>default</servlet-name> 3 <url-pattern>*.js</url-pattern> 4 <url-pattern>*.css</url-pattern> 5 <url-pattern>/assets/*"</url-pattern> 6 <url-pattern>/images/*</url-pattern> 7 </servlet-mapping>
但是当前的设置必须在Spring的Dispatcher的前面
1 <servlet> 2 <servlet-name>SpringMVC</servlet-name> 3 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 4 <init-param> 5 <param-name>contextConfigLocation</param-name> 6 <param-value>classpath:spring-mvc.xml</param-value> 7 </init-param> 8 <load-on-startup>1</load-on-startup> 9 <async-supported>true</async-supported> 10 </servlet> 11 <servlet-mapping> 12 <servlet-name>SpringMVC</servlet-name> 13 <url-pattern>*.do</url-pattern> 14 </servlet-mapping>
这样设置,Spring就会只针对以'.do'结尾的请求进行处理,不再维护静态资源