码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-08-09 23:12:08      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:sources   解决   contex   efault   location   bubuko   ping   pre   package   

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>


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

标签:sources   解决   contex   efault   location   bubuko   ping   pre   package   

原文地址:https://www.cnblogs.com/hy162050430/p/9452061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!