2017-03-31 23 views
0

これはMavenを使用したSpringMVCでの私の最初のアプリケーションです。 ここにアプリケーションの構造を示します。HTTPステータス404 - ページが見つかりません。 SpringMVCエラー

enter image description here

コントローラーコード:

enter image description here

私はindex.jspの中のリンクをクリックするとページが

のindex.jspがこれを持っているhelloworld.jspために横断しなければなりませんリンク:

<h3> 
     <a href="hello?name=Eric">Click Here</a> 
    </h3> 

helloworld.jsp

<h2> 
     ${message} ${name} 
    </h2> 

ディスパッチャサーブレットのコード:

enter image description here

更新:web.xmlファイル。

enter image description here

私はそれは愚かな質問だということを理解しますが、SpringMVC構造への初心者として、私は、エラーを見つけることができないのです。助けてください!

春が始まります。 これはホームページです。リンクをクリックするとhelloworld.jspに移動します。

enter image description here

そして、これはのpom.xmlです。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

にxsi:schemaLocationの= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion> 
<groupId>demoproject</groupId> 
<artifactId>demoMVC</artifactId> 

<packaging>war</packaging> 
<version>0.0.1-SNAPSHOT</version> 
<name>demoMVC Maven Webapp</name> 
<url>http://maven.apache.org</url> 
<properties> 
    <spring.version>4.0.1.RELEASE</spring.version> 
</properties> 
<dependencies> 
<dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>3.8.1</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    </dependencies> 
<build> 
    <finalName>demoMVC</finalName> 
    <directory>${basedir}/target</directory> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.3</version> 
       <configuration> 
         <source>1.8</source> 
         <target>1.8</target> 
         <showWarnings>true</showWarnings> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    </project> 

コンソール:ログに

WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:demoMVC' did not find a matching property. 
    Mar 31, 2017 1:22:08 PM org.apache.coyote.AbstractProtocol init 
    INFO: Initializing ProtocolHandler ["http-bio-8080"] 
    Mar 31, 2017 1:22:08 PM org.apache.coyote.AbstractProtocol init 
    INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
    Mar 31, 2017 1:22:08 PM org.apache.catalina.startup.Catalina load 
    INFO: Initialization processed in 1005 ms 
    Mar 31, 2017 1:22:08 PM org.apache.catalina.core.StandardService startInternal 
    INFO: Starting service Catalina 
    Mar 31, 2017 1:22:08 PM org.apache.catalina.core.StandardEngine startInternal 
    INFO: Starting Servlet Engine: Apache Tomcat/7.0.34 
    Mar 31, 2017 1:22:12 PM org.apache.catalina.core.ApplicationContext log 
    INFO: No Spring WebApplicationInitializer types detected on classpath 
    Mar 31, 2017 1:22:12 PM org.apache.coyote.AbstractProtocol start 
    INFO: Starting ProtocolHandler ["http-bio-8080"] 
    Mar 31, 2017 1:22:12 PM org.apache.coyote.AbstractProtocol start 
    INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
    Mar 31, 2017 1:22:12 PM org.apache.catalina.startup.Catalina start 
    INFO: Server startup in 3739 ms 
+0

いいですね。 pom.xmlはどうですか?また、ログは何ですか?春が始まりますか?ディスパッチャがリクエストを取得していますか? –

+0

こんにちは、私は質問を更新しました。ありがとうございました。 – trin

+0

リンクをクリックするとログはどうなりますか? –

答えて

0

ます

19:05:56,530 INFO [io.undertow.servlet] (ServerService Thread Pool -- 106) Initializing Spring FrameworkServlet 'mvc-dispatcher' 
19:05:56,531 INFO [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 106) FrameworkServlet 'mvc-dispatcher': initialization started 
19:05:56,547 INFO [org.springframework.web.context.support.XmlWebApplicationContext] (ServerService Thread Pool -- 106) Refreshing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Fri Mar 31 19:05:56 UTC 2017]; root of context hierarchy 
19:05:56,584 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 106) Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml] 
19:05:56,741 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 106) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
19:05:56,859 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 106) Mapped "{[/hello],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto protected org.springframework.web.servlet.ModelAndView com.crramirez.HelloWorldController.showMessage(java.lang.String) throws java.lang.Exception 
19:05:57,084 INFO [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 106) FrameworkServlet 'mvc-dispatcher': initialization completed in 553 ms 

Del web.xmlのETEこれらの行:

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

と、このプログラムでは

ディスパッチャ-servlet.xmlからにMVC-ディスパッチャ-servlet.xmlをWEB-INF内のファイルの名前を変更する必要があり作業。

+0

私にとってはうまくいかなかった。 – trin

+0

私の答えが更新されました。今はうまくいきます。 –

+0

こんにちは、私はあなたが示唆したようにコードを更新しました。それでも404エラーを出す。また、コンソールのようなものは表示されません。 – trin

関連する問題