解决 spring mvc 静态资源映射问题

1 将DefaultServlet-servlet.xml的<beans> 换成下面的

2添加 <mvc:annotation-driven/>
3 添加 <mvc:resources mapping="/resources/**" location="/images/"/>
4 将jsp页面的  images 换成 resources

 


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 使用注解的包,包括子集 -->
<context:component-scan base-package="controller"/>
<!--支持对象与json之间的转换-->
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/images/"/>

<!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp"></property>
</bean>

</beans>


posted @ 2018-08-09 22:08  大长腿  阅读(238)  评论(0编辑  收藏  举报