2017-03-04 45 views
1

錯誤葛亭:警告:未找到HTTP請求與URI映射在DispatcherServlet的與名稱telusuko [/ SpringTest /添加]

2017年3月3日下午7點06分58秒org.springframework.web.servlet.PageNotFound noHandlerFound 警告:沒有找到映射與URI HTTP請求中的DispatcherServlet名爲 'telusuko'

調用此

http://localhost:8085/SpringTest/index.jsp網址工作正常[/ SpringTest /添加。

​​不工作的404錯誤讓

AddController:

package com.springs; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 

@Controller 
public class AddController { 

    @RequestMapping(value="/add") 
    public String add(){ 

     return "display.jsp"; 
    //System.out.println("work"); 
    } 
} 

telusuko-servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:ctx="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-2.5.xsd "> 
    <ctx:annotation-config></ctx:annotation-config> 
    <ctx:component-scan base-package="com.springs"></ctx:component-scan> 
    </beans> 

的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>telusuko</servlet-name> 
     <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>telusuko</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

的index.jsp:

<html> 
<body> 
<h2>Hello World!</h2> 

<form action="add"> 
<input type="text" name="t1" /> 
<input type="text" name="t2" /> 
<input type="submit" /> 

</form> 

</body> 
</html> 

回答

0

當您的調度員servel.xml這是缺少

  

<bean 
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
<propertyname="prefix"> 

檢查此鏈接

https://examples.javacodegeeks.com/enterprise-java/spring/mvc/spring-mvc-view-resolver-example/

+0

沒有使用任何其他建議? – srinivas

+0

嘗試從回車中刪除「.Jsp」,並在評論中打印我提交後的URL – OEH

+0

我是用system.out.println代替jsp文件編寫的,甚至無法運行。 DispatcherServlet無法使用@Controller查找配置的類 – srinivas

0
    的第6章,它通常發生
  • 使用Dynamic web項目重新創建項目。
  • 之後,右鍵點擊項目,去配置並選擇「轉換到MAVEN項目」。
1

確保您創建的包和類 '的src/main/java的' 和在 '的src/main/資源'

相關問題