2016-05-24 7 views
-2

以下のコードを実行中に404エラーが発生しました。すべてここでうまく見えますが、私はまだ404エラーを取得しています。私はこれを解決するのに役立ちます。Spring MVCのHelloプログラム

の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" 
    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>Hello Spring</display-name> 

      <servlet> 
      <servlet-name>hello</servlet-name> 
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
      <load-on-startup>1</load-on-startup> 
      </servlet> 
      <servlet-mapping> 
      <servlet-name>hello</servlet-name> 
      <url-pattern>/</url-pattern> 
     </servlet-mapping> 
      <welcome-file-list> 
      <welcome-file>index.jsp</welcome-file> 
      </welcome-file-list> 
      </web-app><br/> 

ハローservlet.xml

<?xml version="1.0" encoding="UTF-8"?> 

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

<context:component-scan basepackage="com.hello"/> 
<bean class="org.springframework.web.servlet.view.InternalResouceViewResolver"> 
<property name="prefix" value="/jsp/" /> 
<property name="suffix" value=".jsp"/> 
</bean> 
</beans></br> 

HelloController

@Controller 
@RequestMapping 
public class HelloController { 
    @RequestMapping("/hello") 
    public ModelAndView getHello() 
    { 
     return new ModelAndView("hellopage","hellomessage","Welcome Spring MVC!!!"); 
    } 

}</br> 

hellopage

<html> 
<body> 
<h1>${hellomessage}</h1> 
</body> 
</html> 
+0

あなたが使用しているスプリングジャーのバージョンは何ですか? –

+0

プロジェクト名とコントローラクラスのパッケージ名は何ですか? –

+0

見つかったhttp://www.tutorialsdesk.com/2016/01/spring-mvc-hello-world-tutorial-with.html Spring MVCのHello Worldサンプルの例 –

答えて

0

Spring 4.x.xの場合、ディスパッチャサーブレットのコンフィグの<beans xsi:schemaLocation"">(あなたの場合はhello-servlet.xml)でバージョンを言及する必要はありません。以下のように更新してください。

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.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.xsd"> 

<context:component-scan basepackage="com.hello"/> 

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

はい、変更しましたが、同じエラーが発生しました – user3912862

+0

WEB-INF/libフォルダにjarファイルを置いていますか? –

+0

また、InternalViewResolverではなくInternalResouceViewResolverに変更します –

0

Spring-Bootで始めるとどうなりますか?あなたは努力することなく、最初からあなたのためにすべてを構築し、納得させる春から始めることができます。あなたはまた、春のツールスイートをダウンロードし、それを行う方法を学ぶための例から新しいプロジェクトを作成することができます

http://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-first-application.html

:ここでは例you'rが探しのためのスタート地点です。そこに多くの素敵なチュートリアルがあります:)

私は助けて欲しい!

ありがとうございます

関連する問題