有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java警告:在名为telusuko的DispatcherServlet中找不到URI为[/SpringTest/add]的HTTP请求的映射

获取时出错:

2017年3月3日7:06:58下午组织。springframework。网状物servlet。PageNotFound noHandlerFound 警告:在名为“telusuko”的DispatcherServlet中找不到URI为[/SpringTest/add]的HTTP请求的映射

从这里呼叫

http://localhost:8085/SpringTest/index.jspurl工作正常

http://localhost:8085/SpringTest/add?t1=dfvd&t2=vdfvfd不工作404获取错误

添加控制器:

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>

网络。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>

索引。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>

共 (3) 个答案

  1. # 1 楼答案

    确保您正在“src/main/java”和“src/main/参考资料”中创建包和类

  2. # 2 楼答案

    • 使用动态web项目重新创建项目
    • 在右键单击project之后,转到configure并选择“convert to MAVEN project”