2016-09-07 59 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