图片资源不能访问
<img src="${pageContext.request.contextPath}/photo/1.png" alt="">
<!-- 拦截所有,不包括jsp,包含.js .png.css (建议使用) -->
<url-pattern>/</url-pattern>
解决方案一(简单)
<mvc:default-servlet-handler/>
解决方案二(性能快,开发推荐)
- 采用spring自带的
<mvc:resources>
<mvc:annotation-driven />
<mvc:resources location="/img/" mapping="/img/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/css/" mapping="/css/**"/>
- 说明
/static为示例目录
(springmvc.xml)
(1) location表示webapp目录下的static包下的所有文件;
(2) mapping表示以/static开头的所有请求路径,如/static/a 或者/static/a/b;
(3) 该配置的作用是:DispatcherServlet不会拦截以/static开头的所有请求路径,并当作静态资源交由Servlet处理