我打字的URL後收到此錯誤 本地主機:8080 /的HelloWebSpring MVC的HTTP狀態404錯誤
HTTP Status 404 - /HelloWeb
type Status report
message /HelloWeb
description The requested resource is not available.
Apache Tomcat/7.0.30
我不能夠解決這個問題,請幫助別人 這裏是我所需要做的文件執行此Spring MVC的招呼程序
HelloController.java
package com.tutorialspoint;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
的hello.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
的web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
的HelloWeb-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"
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 base-package="com.tutorialspoint" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
,這裏是我的項目層次
的HelloWeb
SRC
com.tutorialspoint
的WebContent
JSP
的hello.jsp
META-INF
MANIFEST.MF
WEB_INF
LIB
的HelloWeb-servlet.xml中
的index.jsp
的web.xml
對不起,我忘了包括以下我從
tutorialspoint.com/spring/spring_mvc_hello_world_example.htm
我也得到同樣的錯誤。你有解決方案嗎? – Chetan 2015-02-18 06:24:13
@Chetu不,我沒有。 – 2015-02-18 06:58:09