Java @RequestMapping无法正常工作';应该是的

Java @RequestMapping无法正常工作';应该是的,java,spring,Java,Spring,让Tomcat启动并自动显示index.jsp文件的内容没有问题。然而,当我尝试使用@Controller&@RequestMapping时,我遇到了一个错误。这是我的控制器类 package fifteenth; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public

让Tomcat启动并自动显示index.jsp文件的内容没有问题。然而,当我尝试使用@Controller&@RequestMapping时,我遇到了一个错误。这是我的控制器类

package fifteenth;

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

    @Controller
    public class AddController {

        @RequestMapping("/add")
        public String add() {
            return "display.jsp";
        }

    }
这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
    <display-name>Fifteenth</display-name>
        <servlet-name>fifteenth</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>fifteenth</servlet-name>
        <url-pattern>*.htm</url-pattern>

    </servlet-mapping>
</web-app>

十五
第十五
org.springframework.web.servlet.DispatcherServlet
第十五
*.htm
我相信这就是我的调度程序servlet,名为tenrth-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="fifteenth"></ctx:component-scan>
</beans>

myindex.jsp文件的内容

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="add">
<input type="text" name="t1">
<input type="text" name="t2">
<input type="submit">

</form>
</body>
</html>

在此处插入标题

如前所述,index.jsp工作正常,但当我单击按钮时,我得到一个404未找到错误,即“Therth/add”未找到。

您的servlet映射设置为映射
*.htm
URL


尝试将表单操作更改为
add.htm
,应该会更好。

只是想知道这些天是谁强迫你使用Spring2.5的?不要对自己太苛刻;)@ThomasWeglinski我正在网上学习一个教程。@micahkam-我希望这个解决方案对你有用。不要忘记将答案标记为已接受,以便将来的访问者也可以自信地使用该解决方案。要将答案标记为已接受,您需要单击大复选标记(✓) 答案左边。您可以查看以了解更多信息。如果有任何疑问/问题,请随时发表评论。至少我现在遇到了一个我没有遇到的错误。ClassNotFoundException for org.springframework.web.servlet.DispatcherServlet