springmvc静态资源配置

来源:互联网 发布:网络营销策划书的作用 编辑:程序博客网 时间:2024/06/05 03:17

1、静态资源配置

[html] view plain copy
  1. <mvc:default-servlet-handler/>   

2、完整配置

[html] view plain copy
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.  xmlns:context="http://www.springframework.org/schema/context"  
  3.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.  xmlns:mvc="http://www.springframework.org/schema/mvc"   
  5.  xsi:schemaLocation="  
  6. http://www.springframework.org/schema/beans  
  7. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  8. http://www.springframework.org/schema/context  
  9. http://www.springframework.org/schema/context/spring-context-3.0.xsd  
  10. http://www.springframework.org/schema/mvc   
  11. http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">  
  12.  <context:component-scan base-package="com.nextgame.web" />  
  13.  <!--mvc静态资源访问 -->  
  14.  <mvc:default-servlet-handler/>   
  15.  <bean  
  16.  class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  17.  <property name="prefix">  
  18.  <value>/WEB-INF/views/</value>  
  19.  </property>  
  20.  <property name="suffix">  
  21.  <value>.jsp</value>  
  22.  </property>  
  23.  </bean>  
  24. </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、浏览器访问静态图片

原创粉丝点击