在DispatcherServlet中找不到名称为URI [/ SpringMVCDemo / add]的HTTP请求的映射

时间:2019-03-29 08:16:25

标签: spring maven

我是Spring MVC的新手。我知道我关于stackoverflow的问题有很多答案,但是不幸的是,这些答案都无法解决亩问题。我正在尝试实现简单的mvc代码,但无法识别我的错误:我收到警告:“在DispatcherServlet中,名称为“ sachin”的URI [/ SpringMVCDemo / add]的HTTP请求未找到映射””

这是index.jsp

<html>
<body>
<form action="add">
    <input type="text" name="t1" /> <input type="text" name="t2" /> 
    <input type="submit"/>
</form>
</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>sachin</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>sachin</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

我使用@Controller和@RequestMapping批注的控制器

package com.sachin;

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

@Controller
public class AddController {

@RequestMapping("/add")
public void add() {
    System.out.println("I am in AddController");
    }
}

我的sachin-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<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.sachin.*"></ctx:component-scan>
</beans>

欢迎提出任何建议。

0 个答案:

没有答案