您的位置:首页 > 编程语言 > Java开发

SpringMVC配置静态资源访问

2014-09-20 16:11 519 查看

1、静态资源配置

<mvc:default-servlet-handler/>


2、完整配置

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.nextgame.web" />
<!--mvc静态资源访问 -->
<mvc:default-servlet-handler/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

3、问题

the prefix "mvc" for element "mvc:default-servlet-handler" is not bound

在xml的beans中添加 

xmlns:mvc="http://www.springframework.org/schema/mvc" 

xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"

4、静态资源存放位置

静态资源存放在工程中的webapp目录下,可自定义子目录。



5、浏览器访问静态图片

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: