2017-02-10 96 views
0

我想學習如何在服務器上運行Spring MVC項目,並且出現http 404錯誤..我正在使用Eclipse Luna 4.4.1,Tomcat 8 我看不到錯誤。HTTP狀態404 Eclipse項目錯誤

控制器類

package com.spring.controller; 

    import org.springframework.stereotype.Controller; 
    import org.springframework.web.bind.annotation.RequestMapping; 

    @Controller 
    public class OffersController { 

     @RequestMapping("/") 
     public String showHome() { 
      return "home"; 
     } 
    } 

的JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
     pageEncoding="ISO-8859-1"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-  8859-1"> 
    <title>Insert title here</title> 
    </head> 
    <body> 
    Hi there! 
    </body> 
    </html> 

THER的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:mvc="http://www.springframework.org/schema/mvc" 
     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.2.xsd 
      http://www.springframework.org/schema/beans   ://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 


     <context:component-scan base-package="com.maurice.controllers"> 
     </context:component-scan> 
     <mvc:annotation-driven></mvc:annotation-driven> 

     <bean id="jspViewResolver" 
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
      <property name="prefix" value="/WEB-INF/jsps/"></property> 
      <property name="suffix" value=".jsp"></property> 
     </bean> 
    </beans> 

的web.xml

<?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" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" 
    version="2.5"> 

    <display-name>Own2</display-name> 

     <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
     <welcome-file>index.htm</welcome-file> 
     <welcome-file>index.jsp</welcome-file> 
     <welcome-file>default.html</welcome-file> 
     <welcome-file>default.htm</welcome-file> 
     <welcome-file>default.jsp</welcome-file> 
     </welcome-file-list> 
     <servlet> 
     <description></description> 
     <display-name>offers</display-name> 
     <servlet-name>offers</servlet-name> 
     <servlet-  class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 

     <load-on-startup>1</load-on-startup> 
     </servlet> 
     <servlet-mapping> 
     <servlet-name>offers</servlet-name> 
     <url-pattern>/</url-pattern> 
     </servlet-mapping> 
    </web-app> 
+0

這已經:

<?xml version="1.0" encoding="UTF-8"?> <Context path="/Own2"/> 

從Tomcat文檔設置,而不是錯誤的來源: user7535663

回答

0

此基礎上,似乎你沒有在Tomcat中定義了上下文中的錯誤消息。

包括一個名爲的context.xml文件,到META-INF文件夾,與內容:

Tomcat Context Container Documentation

Individual Context elements may be explicitly defined:

In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.