私は以前に尋ねられた同様の質問を見ました。私は彼らに提供された解決策を試みたが、同じ問題に直面していた。 私は単純なhello world spring mvcアプリケーションを実行しようとしています。私は取得しています 出力は、コードファイル以下は、コンソールでHTTP Status 404コンソール出力:org.springframework.web.servlet.PageNotFound noHandlerFound HTTPステータス404:リクエストされたリソースは利用できません
ある I can see following message.
。
の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" version="3.0">
<display-name>HelloWorldApplication</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/welcome.jsp</url-pattern>
<url-pattern>/index.jsp</url-pattern>
<url-pattern>/welcome.html</url-pattern>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
のHelloWorld-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 base-package="com.HelloWorld.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
HelloWorldMain.java
package com.HelloWorld.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/*
* author: Siddhesh Jethe
*
*/
@Controller
public class HelloWorldMain {
@RequestMapping("/welcome")
public ModelAndView helloWorld() {
String message = "<br><div style='text-align:center;'>"
+ "<h3>********** Hello World </h3> Welcome**********</div><br><br>";
return new ModelAndView("welcome", "message", message);
}
}
index.jspを
<html>
<head>
<title>Test project</title>
<style type="text/css">
</style>
</head>
<body>
<br>
<div style="text-align:center">
<h2>
test<br> <br>
</h2>
<h3>
<a href="welcome.html">Click here to See Welcome Message... </a>
</h3>
</div>
</body>
</html>
返信の遅れのためのお詫び。私はあなたが提案したものを試しました。 http:// localhost:8080/HelloWorld/welcomeです。しかし、それは仕事をしなかった。それでも同じ問題に直面している。 – IamSJ
私はhttp:// localhost:8080/HelloWorld/welcome.jspを試しました。 。それは今働いている。しかし、アプリケーションを実行するたびに、 "http:// localhost:8080/HelloWorld /"の前に "welcome.jsp"を追加する必要があります。どのようにしても、私は直接「welcome.jsp」を手動で追加することなく出力画面を得ることができます。以前のソリューションをありがとう。 – IamSJ