Spring MVC訪問靜態頁面,在servlet.xml中加了mvc:resources mapping 就會出現404錯誤

初學Spring MVC,遇到各種錯誤,逐一整理記下。


問題:

首先貼上StaticPages-servlet.xml

<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.yiibai"/>
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />
   </bean>
   


   <mvc:resources mapping="/pages/**" location="/WEB-INF/pages/" />


</beans>


訪問出現404錯誤



對比了半天,後來去掉

   <mvc:resources mapping="/pages/**" location="/WEB-INF/pages/" /> 再訪問是可以的,但是去掉了這一句,就無法訪問指定的html了。



解決辦法:

加上

<mvc:annotation-driven/> 

即:

 <mvc:resources mapping="/pages/**" location="/WEB-INF/pages/" />

 <mvc:annotation-driven/> 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章