SpringMVC配置靜態資源訪問

OnnePiece發表於2014-09-20

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、瀏覽器訪問靜態圖片




相關文章