使用SpringMVC的时候,如果在web.xml文件中设置url-pattern为/的话,那么当引入一个js文件,css文件等请求会被SpringMVC所拦截,导致文件不能引入,可以更改url-pattern,使其为特定的后后缀(如.do,.html等),除此之外,SpringMVC提供了一个标签,可以让SpringMVC不是拦截这个请求
这个标签是<mvc:resource>
首先,要使用这个标签,要在SpringMVC的xml文件上注明,如下
<beans xmlns="http://www.springframework.org/schema/beans"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
两个http,以及xmlns:mvc(省略其他),这样就可以使用mvc标签
然后使用方式如下
<mvc:resources location="/img/" mapping="/image/*"/>
这意思是,location指定文件的位置,mapping指定访问该文件所对应的映射
如,在根路径下有一img文件夹,里面有a.jpg这张图片,那么,访问的时候就是/image/a.jpg,而使用/img/a.jpg是访问不到的,