我已經嘗試過所有的事情,試圖弄清楚這裏發生了什麼。我無法讓我的控制器響應我輸入的URL並繼續得到HTTP 404錯誤。我使用在Spring MVC中的RequestMapping失敗
網址 - http://localhost:8080/projectHub/getHomepage.html
projectHub-servletConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
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-4.0.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.projectHub.controllers"></context:component-scan>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="WEB-INF/jsp/" p:suffix=".jsp" />
</beans>
homepage.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ProjectHub Homepage</title>
</head>
<body>
<h1>${titleHomepage}</h1>
<p>WTF</p>
</body>
</html>
ProjectHubController.java
@Controller
public class ProjectHubController {
@RequestMapping(value="/getHomepage")
public String getHomepage(Model model) {
model.addAttribute("titleHomepage", "ProjectHub");
return "homepage";
}
}
的web.xml
<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>ProjectHub</display-name>
<servlet>
<servlet-name>projectHub</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/projectHub-servletConfig.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>projectHub</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
嘗試使用沒有解決問題的「.html」 – rorschach
的網址。 – TheDeveloper
您是否也納入了其他答案的變化? – rorschach