2014-04-03 141 views
0

我無法弄清楚這段代碼中的問題。我沒有得到主頁,也沒有在控制檯中顯示錯誤。spring mvc HTTP狀態404基本啓動

的web.xml:

<web-app> 
    <display-name>Myapp</display-name> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>*.do</url-pattern> 
    </servlet-mapping> 

</web-app> 

調度-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/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 
    <mvc:annotation-driven /> 
    <context:component-scan base-package="com.sim.market.controller" /> 

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

</beans> 

首頁控制器:

package com.sim.market.controller; 

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

@Controller 
@RequestMapping("/home") 
public class HomeController { 

    public String showHome(){ 
     System.out.println("calloing"); 
     return "home"; 
    } 
} 

在控制檯上沒有錯誤,但在瀏覽器錯誤是

HTTP Status 404 - 

type Status report 

message 

description The requested resource is not available. 

enter image description here 誰能幫助我嗎?提前致謝。

從日食它運行應用程序時顯示以下日誌:

Apr 03, 2014 6:54:30 PM org.apache.catalina.core.AprLifecycleListener init 
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-7-oracle/jre/lib/i386/client:/usr/lib/jvm/java-7-oracle/jre/lib/i386::/usr/java/packages/lib/i386:/lib:/usr/lib 
Apr 03, 2014 6:54:30 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:MarketApp' did not find a matching property. 
Apr 03, 2014 6:54:30 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8080"] 
Apr 03, 2014 6:54:30 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
Apr 03, 2014 6:54:30 PM org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 960 ms 
Apr 03, 2014 6:54:30 PM org.apache.catalina.core.StandardService startInternal 
INFO: Starting service Catalina 
Apr 03, 2014 6:54:30 PM org.apache.catalina.core.StandardEngine startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.37 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined 
Apr 03, 2014 6:54:31 PM org.apache.catalina.loader.WebappClassLoader validateJarFile 
INFO: validateJarFile(/home/webwerks/sachin/workspaces/sedi_workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/MarketApp/WEB-INF/lib/servlet-api-3.0-alpha-1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined 
Apr 03, 2014 6:54:38 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined 
Apr 03, 2014 6:54:39 PM org.apache.catalina.startup.TaglibUriRule body 
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined 
Apr 03, 2014 6:54:39 PM org.apache.catalina.core.ApplicationContext log 
INFO: No Spring WebApplicationInitializer types detected on classpath 
Apr 03, 2014 6:54:39 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-8080"] 
Apr 03, 2014 6:54:39 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
Apr 03, 2014 6:54:39 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 8143 ms 

,當我打電話像home.do 資源它表明:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
SLF4J: Defaulting to no-operation (NOP) logger implementation 
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 
Apr 03, 2014 6:56:09 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'dispatcher' 
+1

您使用什麼URL訪問您的資源?你的Web應用程序是否正確地部署在你的Web服務器上,並且你的Web服務器是否正常運行? –

+0

http:// localhost:8080/MyApp/home.do – coreJavare

+0

我沒有看到@coreJavare調用的URL。刪除我的答案。 – Prasad

回答

0

註釋與@RequestMappingshowHome()的方法來確定它作爲處理程序。沒有它,你的控制器沒有處理方法,因此沒有處理請求。

很顯然,您會在@RequestMapping上添加限制,例如處理哪些HTTP方法,可能包含哪些標頭,甚至專門處理應該處理的路徑。

+0

剛做完添加相同: \t @RequestMapping(方法= RequestMethod.GET),但還是同樣的錯誤 – coreJavare

+0

@core是應用程序部署?日誌顯示了什麼? –

+0

請檢查問題,因爲我已經添加log – coreJavare

0

您需要爲您的請求映射。

@RequestMapping (value = "/showhome", method = {RequestMethod.GET, RequestMethod.POST}) 
public String showHome(ModelMap model, HttpServletRequest request) { } 

就像那樣。

+0

試過這其中也但還是同樣的錯誤 – coreJavare

+0

你的要求應該是localhost /項目名/家庭/ showHome –

1

那麼你應該在web.xml中添加此

<welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 

添加該代碼段

的index.jsp
<meta HTTP-EQUIV="REFRESH" content="0; url=${pageContext.request.contextPath}/home.do"> 

每次我提出申請時發現,這是一個很好的選擇,在Spring MVC

+0

沒有它,這也沒有奏效。 – coreJavare

+0

這個改變會是什麼? –

+0

首先它將被重定向到index.jsp頁面,該頁面將刷新並重定向到您指定的URL ...此URl應該是您要執行的控制器方法的映射 – tarkikshah