在DispatcherServlet中找不到URI [/SampleSpringMaven/hello.html]的映射,名称为“dispatcher”

时间:2016-08-20 04:22:02

标签: spring-mvc

我是Spring MVC的新手,为Spring MVC创建了基本的hello world示例,但收到了消息:

  

在带有名称调度程序的DispatcherServlet中使用URI [/SampleSpringMaven/hello.html]发现HTTP请求的HNo映射

的index.jsp

<html>
<body>
<h2>Hello World!</h2>
<a href="hello.html">Call Controller</a>
</body>
</html>

然后我创建了web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
  <servlet-name>dispatcher</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>

此Dispatcher-servelet.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" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc    
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd    
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
    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.mvc.controller" />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <mvc:annotation-driven/>
    <context:annotation-config/>
</beans>

然后我创建了HelloWorldController.java

package com.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {

    @RequestMapping("SampleSpringMaven/hello")
    public ModelAndView printMessage()
    {
        String message = "Hello World, Spring 3.0!";
        System.out.println("reached here");
        return new ModelAndView("hello", "message", message);
    }
}

但是无法获得响应和请求的资源不可用来自Tomcat日志的页面我看到错误:在带有名称调度程序的DispatcherServlet中找不到带有URI [/SampleSpringMaven/hello.html]的HTTP请求的映射

0 个答案:

没有答案