2017-11-22 2 views
0

봄 MVC를 처음 사용합니다. 작은 hello world 앱을 만들려고했지만 예상대로 실행되지 않습니다. 난 항상 오류 org.springframework.web.servlet.DispatcherServlet noHandlerFound 경고를 받고 오전 : 없음 매핑 [/FitnessTracker/greeting.html] 이름의 DispatcherServlet에 'fitTrackerServlet'org.springframework.web.servlet.DispatcherServlet noHandlerFound : 봄 MVC

나는 이것을 알고 URI와 HTTP 요청을 찾을 수 없습니다 오류는 매우 일반적이며 Google에서 사용할 수있는 많은 링크가 있지만 그 중 누구도 나를 위해 일하지 않았습니다. 어떤 도움을 주시면 감사하겠습니다. 여기

는 코드

HelloController.java

@Controller 
public class HelloController { 

@RequestMapping(value = "/greeting")  
public String sayHello(Model model) { 
model.addAttribute("greeting","Hello World!!!!"); 
return "hello"; 
}} 

Hello.jsp 라이다

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<!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=UTF-8"> 
<title> 
Insert title here 
</title> 
</head> 
<body> 
<h1> 
${greeting} 
</h1> 
</body> 
</html> 

fitTrackerServlet-servlet.xml에

012 3,516,
<?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:p="http://www.springframework.org/schema/p" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.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.xsd"> 

<mvc:annotation-driven/> 
<context:annotation-config/> 
<context:component-scan base-package="com.firstspringmvc.controller"/> 
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" 
     p:suffix=".jsp"/> 
</beans> 

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" 
    xmlns:web="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>Archetype Created Web Application</display-name> 
    <servlet> 
    <servlet-name>fitTrackerServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>fitTrackerServlet</servlet-name> 
     <url-pattern>*.html</url-pattern> 
    </servlet-mapping> 
</web-app> 

의 URL /greeting은 끝의 .html을 가지고 있지 않기 때문에, 서블릿이의 DispatcherServlet을 사용하지 않을 것입니다 enter image description here

+0

봅니다 이름 "는 contextConfigLocation"가치와 서블릿 (고화질)에 XML의 경로는 init-PARAM 같은 XML을 추가. 컨트롤러 정의가로드되지 않았을 수 있습니다. – helospark

+0

'/'이렇게 URL 패턴을주고 한 번 시도해보십시오. JSP 페이지가 여기 있습니다. JSP 응용 프로그램에서 html이 아닙니다. – Hema

+0

@helospark 잘 시도했지만 작동하지 않았습니다. –

답변

0

프로젝트 구조, *.html 패턴이/인사말과 일치하지 않기 때문에 404로 표시됩니다.

는 당신의 web.xml을 변경 :

<servlet-mapping> 
    <servlet-name>fitTrackerServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 
관련 문제