2014-09-24 65 views
1

這是我的調度程序文件。我添加了架構/ mvc的名稱空間,內容及其相應的位置...添加mvc:resources標籤的彈簧

現在,當我使用下面的xml運行我的應用程序時,我的頁面找不到應用程序,但是當我刪除xmlns:mvc和資源標記它的工作沒有任何問題......

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-2.5.xsd 
    "> 


<context:component-scan base-package="com.school.controller" /> 

<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" > 
      <property name="prefix"> 
      <value>/WEB-INF/pages/</value> 
      </property> 
      <property name="suffix"> 
      <value>.jsp</value> 
      </property> 
</bean> 
<mvc:resources mapping="/resources/**" location="/resources/static/" /> 

網址 - http://localhost:8080/SchoolManagement/

的web.xml

<!DOCTYPE web-app PUBLIC 
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd" > 

<web-app> 
    <display-name>Archetype Created Web Application</display-name> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> 
    </context-param> 

    <listener> 
     <listener-class> 
      org.springframework.web.context.ContextLoaderListener 
     </listener-class> 
    </listener> 

    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

</web-app> 

的Servlet -

package com.school.controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.servlet.ModelAndView; 

import com.school.beans.Login; 

@Controller 
public class Logincontroller { 
    @RequestMapping(value = "/", method = RequestMethod.GET) 
    public ModelAndView student() { 
     return new ModelAndView("login", "loginform", new Login()); 
    } 
} 

回答

0
<mvc:resources mapping="/resources/**" location="/resources/static/" /> 

這個標籤基本上是說,如果在URI路徑的開頭 「/資源/」,然後返回位於 「/資源/靜態/」

檢查文件您的文件(圖片,CSS等)的locatled在<your_webapp_root>/resources/static/

編輯:

我還注意到您正在使用不同版本的命名空間聲明:

spring-mvc-3.0.xsd 
spring-beans-2.5.xsd 
spring-context-2.5.xsd 

檢查你的依賴,並使用正確的版本