2016-04-14 91 views
0

我無法得到的結果 從控制檯錯誤HTTP請求沒有映射爲:發現與URI [//SpringMVCJavatpoint/hello.html在DispatcherServlet的名稱爲「春秋」

org.springframework.web .servlet.DispatcherServlet noHandlerFound 警告:未發現與URI [//SpringMVCJavatpoint/hello.html]在DispatcherServlet的與名稱 '彈簧'

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> 
HTTP請求映射

彈簧-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> 
+0

哪裏是調用'/ SpringMVCJavatpoint/hello.htm'的文件? – Reimeus

+1

這幾乎是[第300個問題](http://stackoverflow.com/search?q=%22No+mapping+found+for+HTTP+request+with+URI%22+%22in+DispatcherServlet+with+name% 22)關於同一主題! [spring]標籤管理員在哪裏?哪一個確切是規範的副本?或者如果沒有這樣的一個,爲什麼不創建/策劃?不是春天,在這裏培養知識基礎是否值得? – BalusC

回答

-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; 
} 

}

相關問題