SpringMVC 静态资源处理使用

195 阅读1分钟

1、配置Spring xml 解决

<!--能够访问.do .action-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--处理 将映射地址直接指向静态文件家 Spring将不会将此映射作为handler-->
<mvc:resources mapping="/images/**" location="/images/"></mvc:resources>

<mvc:resources mapping="/user/**" location="/user/"></mvc:resources>

    <!--当spring没有映射到某个请求时 默认调用servlet处理-->
    <mvc:default-servlet-handler ></mvc:default-servlet-handler>

image.png

2、URL 使用。 pageContext.request.contextPath 定位根目录

<img src="${pageContext.request.contextPath}/user/1.jpg" width="100">