在DispatcherServlet中找不到带有URI [//SpringMVCJavatpoint/hello.html]的HTTP请求的映射,名称为' spring'

时间:2016-04-14 19:35:41

标签: java html spring spring-mvc servlets

我无法得到结果 从控制台错误如下:

org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:在DispatcherServlet中找不到带有URI [//SpringMVCJavatpoint/hello.html]的HTTP请求的映射,名称为' spring'

Web.xml文件

<?xml version="1.0" encoding="UTF-8"?>  
<web-app version="2.5"   
    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_2_5.xsd">   
    <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/*</url-pattern>


    </servlet-mapping>


</web-app>   

spring-servlet.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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="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.xsd
                http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 


    <context:component-scan base-package="com.springMVC"/>
    <!-- <mvc:default-servlet-handler/>-->
    <mvc:annotation-driven />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/WEB-INF/jsp/" />  
        <property name="suffix" value=".jsp" />  
    </bean>

</beans>    

控制器

    package com.springMVC;

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


@Controller

public class HelloWorldController {

    @RequestMapping(value="/hello.html",method=RequestMethod.GET)
    public ModelAndView getAdmissionForm(){
        ModelAndView model1= new ModelAndView("AdmissionForm");
        return model1;
    }

}

AdmissionForm.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>Insert title here</title>
</head>
<body>
<h1>This is admission form</h1>

<form action="/FirstSpringMVCProject/submitAdmissionForm.html" method="post">

        <p>Student Name: <input type="text" name="studentName"/>
        <p>Student Country: <input type="text" name="studentCountry"/>

</form>


</body>
</html>

1 个答案:

答案 0 :(得分:-1)

package com.springMVC;

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

@Controller

public class HelloWorldController {

    @RequestMapping(value="/hello.html",method=RequestMethod.POST)
    public ModelAndView getAdmissionForm(){
    ModelAndView model1= new ModelAndView("AdmissionForm");
    return model1;
}

}