저는 여기서 무엇이 일어나고 있는지 알아 내려고 노력했습니다. 내 컨트롤러가 입력 할 URL에 응답하고 HTTP 404 오류를 계속받을 수 없습니다. 내가 사용하고RequestMapping이 Spring MVC에서 실패했습니다.
URL - http://localhost:8080/projectHub/getHomepage.html
디렉토리 - http://imgur.com/Gv75lwz
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
없이 URL을 사용해보십시오. – TheDeveloper
다른 답변의 변경 사항을 통합 했습니까? – rorschach