2016-09-07 63 views
1

我使用SpringMVC在eclipse IDE中創建了maven項目。 沒有maven的同一個項目運行得非常好,但是在使用maven項目創建它之後,我不確定出了什麼問題。
我的項目在服務器上運行時顯示錯誤頁面未找到。
我的代碼如下
的web.xmlMaven springMVC項目。頁面未加載顯示錯誤頁面未找到

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>LoginMavenSpringMVC</display-name> 
    <servlet> 
    <servlet-name>spring-dispatcher</servlet-name> 
    <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
</servlet> 
<servlet-mapping> 
    <servlet-name>spring-dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 
</web-app> 

調度員的servlet

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:cache="http://www.springframework.org/schema/cache" 
    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 http://www.springframework.org/schema/cache 
     http://www.springframework.org/schema/cache/spring-cache-3.2.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 


    <context:component-scan base-package="com.java.Package.Login"></context:component-scan> 

    <mvc:annotation-driven/> 
    <mvc:resources mapping="/resources/**" location="/resources/theme/" /> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 

     <property name="prefix"> 

      <value>/WEB-INF/views/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 
    <mvc:resources mapping="/resources/**" location="/resources/theme/" /> 

</beans> 

控制器類

package com.java.Package.Login; 

import java.util.Map; 

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

@Controller 
public class LoginController { 

    @RequestMapping(value="/Login.html", method=RequestMethod.GET) 

    public ModelAndView getLoginForm(){ 
     ModelAndView model = new ModelAndView("Login"); 
     System.out.println("working"); 
     return model; 

    } 
} 

我的項目結構
enter image description here

如果我錯了。當我在服務器上運行它,它說找不到網頁。

回答

1

您在web.xml中錯過了下面的spring-dispatcher。

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

    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      classpath:location_of_your_spring_conf_xml 
      eg: /WEB-INF/spring/web-rest-config.xml   
      </param-value> 
    </init-param>  
    <load-on-startup>1</load-on-startup> 
+0

什麼是它的使用 –

+0

爲了給出一個回答乾脆利落,在XML綁到的contextConfigLocation中定義的春天豆製作意識到DispatchServlet什麼春豆在其範圍內的方式。 – user3138997