2016-09-24 4 views
0

저는 여기서 무엇이 일어나고 있는지 알아 내려고 노력했습니다. 내 컨트롤러가 입력 할 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> 
+0

문제가 해결되지 않은 ".html" – rorschach

+0

없이 URL을 사용해보십시오. – TheDeveloper

+0

다른 답변의 변경 사항을 통합 했습니까? – rorschach

답변

0

나는 web.xml에 당신의 URL 패턴이 잘못 생각합니다. "/ *"가 아니고 "/"가되어야합니다.

+0

시도했으나 작동하지 않았습니다. – TheDeveloper

+0

왜 그렇게 생각하십니까? –

-1

HTTP URL은 대소 문자를 구분합니다. 귀하의 URL에있는 projectHub에 자본 P가 있습니까? 대문자 P로 시도하십시오. 끝에 .html을 사용하지 마십시오. 문제점이 지속되면 서버 sysouts도 공유하십시오.