2014-01-28 128 views
-1

我有5個你好世界項目有同樣的錯誤:請求的資源不可用。 Spring MVC

「description:所請求的資源不可用。」

我使用jdk7,tomcat7,maven3.1.1。我總是使用mvn clean/package。

下面是這種情況的一個突出

/WEB-INF/dispatcher-servlet.xml

<?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" 

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"> 

<!-- the package is right(checked it twice) --> 
<context:component-scan base-package="ua.abond.tutor.controller" /> 

<!-- without this tag I get "No mapping found for HTTP request with URI [/SecondSite/hello.htm] in DispatcherServlet with name 'dispatcher'" --> 
<mvc:default-servlet-handler /> 

<!-- also tried mvc:annotation-driven and context:annotation-config tags 
    didnt help too--> 

<bean id="viewResolver" 
         class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
         p:prefix="/WEB-INF/pages/" p:suffix=".jsp"> 
</bean> 
     <!-- prefix is right, if I had permission, I would have shared my root screenshot --> 
</beans> 

/WEB-INF/web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    version="2.5"> 

    <display-name>SecondSite</display-name> 

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

    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>*.htm</url-pattern> 
      <!-- also tried /*, *, /dispatcher/*, /dispatcher/*.htm and/--> 
    </servlet-mapping> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> 
    </context-param> 

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

控制器

和我的頁面

1)的index.jsp

<html> 
<head> 
<title>Tutorial | Spring</title> 
</head> 
<body> 

    <h4> 
     <a href="hello.htm">Click Here</a> 
    </h4> 
</body> 
</html> 

2)WEB-INF /頁/ hello.jsp中------頁面我不能達到

<html> 
<head> 
<title>Tutorial | Spring</title> 
</head> 
<body> 

    <h4>${message}</h4> 
</body> 
</html> 

控制檯

Jan 28, 2014 8:57:15 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: D:\Programmes\JRE7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\iis express\PHP\v5.4;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft SQL ;;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Program Files (x86)\nodejs\ ;C:\Program Files\Apache Software Foundation\apache-maven-3.1.1\bin;C:\Program Files (x86)\Java\jre7\bin;C:\Users\Alex\AppData\Roaming\npm\;. 
Jan 28, 2014 8:57:15 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SecondSite' did not find a matching property. 
Jan 28, 2014 8:57:15 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8080"] 
Jan 28, 2014 8:57:15 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
Jan 28, 2014 8:57:15 PM org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 475 ms 
Jan 28, 2014 8:57:15 PM org.apache.catalina.core.StandardService startInternal 
INFO: Starting service Catalina 
Jan 28, 2014 8:57:15 PM org.apache.catalina.core.StandardEngine startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47 
Jan 28, 2014 8:57:16 PM org.apache.catalina.core.ApplicationContext log 
INFO: No Spring WebApplicationInitializer types detected on classpath 
Jan 28, 2014 8:57:16 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 
Jan 28, 2014 8:57:16 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
INFO: Root WebApplicationContext: initialization started 
Jan 28, 2014 8:57:16 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh 
INFO: Refreshing Root WebApplicationContext: startup date [Tue Jan 28 20:57:16 EET 2014]; root of context hierarchy 
Jan 28, 2014 8:57:16 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] 
Jan 28, 2014 8:57:17 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 
INFO: Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0' 
Jan 28, 2014 8:57:17 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
INFO: Root WebApplicationContext: initialization completed in 692 ms 
Jan 28, 2014 8:57:17 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'dispatcher' 
Jan 28, 2014 8:57:17 PM org.springframework.web.servlet.FrameworkServlet initServletBean 
INFO: FrameworkServlet 'dispatcher': initialization started 
Jan 28, 2014 8:57:17 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh 
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Jan 28 20:57:17 EET 2014]; parent: Root WebApplicationContext 
Jan 28, 2014 8:57:17 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] 
Jan 28, 2014 8:57:17 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 
INFO: Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0' 
Jan 28, 2014 8:57:17 PM org.springframework.web.servlet.FrameworkServlet initServletBean 
INFO: FrameworkServlet 'dispatcher': initialization completed in 178 ms 
Jan 28, 2014 8:57:17 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-8080"] 
Jan 28, 2014 8:57:17 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
Jan 28, 2014 8:57:17 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 2025 ms 
+0

您的應用程序的發佈目錄結構。 –

+0

whatch here: http://imgur.com/IcaIpQm – noobsaibot

+0

是錯誤的瀏覽器錯誤,或在您的服務器日誌?如果這是一個瀏覽器錯誤,也給我們你正在測試的URL – Gus

回答

0

調度程序servlet僅配置爲處理* .htm文件,所以在訪問/ hello時它不起作用。

試試這個:

<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 
+0

這不起作用。 – noobsaibot

0

嘗試用這個,

<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 
+0

也試過這個,它沒有工作 – noobsaibot

+0

清理項目,並嘗試再次運行 –

+0

仍然沒有結果...手下來,我真的不明白爲什麼它不起作用 – noobsaibot

0

<mvc:annotation-driven />在春天的配置。

+0

也沒有幫助。 – noobsaibot

相關問題