私はSpringMVCで新しく、単純なhello worldプログラムを実行しようとしています。しかし、私のブラウザ(http://localhost:8080/FirstspringMVCwithannotation/welcome)でこれを実行すると、HTTPステータス404エラーが出ます。Spring MVCでエラー(HTTPステータス404 - )を取得しています
HelloController.java
package com.example;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;
@Controller
public class HelloController {
@RequestMapping("/welcome")
public ModelAndView helloWorld(){
ModelAndView model=new ModelAndView("HelloPage");
model.addObject("msg","hello world");
return model;
}
}
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>FirstspringMVCwithannotation</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.example" />
<mvc:annotation-driven/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
HelloPage.jsp
:ここでは、コードがあります<html>
<body>
<h1>
First Spring MVC Application Demo
</h1>
<h2>
${msg}
</h2>
</body>
</html>
ここ
私のプロジェクト構造であると私は他のソリューションを参照しようとしたが、それは私のproblem..can誰も私を助けてください解決しない、なぜ私のlibフォルダの下に
をすべて春のjarファイルを追加しましたHTTPステータス404エラーを取得しますか?事前に感謝します
' /' /*のurl-pattern> '、参照してくださいhttp://stackoverflow.com/questions/29792677 –
' @RequestMapping( "/歓迎")へのurl-pattern> 'を変更してみてください'エラーの理由は'/'に変わって作業をする、またはそれに従うコメント – emotionlessbananas
あなたのプロジェクトのファイル構造は何ですか?あなたのjspビューのフォルダパスはどこにありますか? –