java - HTTP 状态 404 - 在 spring-mvc 中使用 RequestMapping 注释未找到
问题描述
这是 index.jsp 文件
<html>
<body>
<form action="add">
<input type="text" name="t1"></br>
<input type="text" name="t2"></br>
<input type="submit">
</form>
</body>
</html>
这是 todo-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.telusko"></context:component-scan>
<mvc:annotation-driven />
<mvc:annotation-driven enable-matrix-variables="true"/>
</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>todo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>todo</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
AddController.java 文件
package com.telusko;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class AddController {
@RequestMapping("/add")
public String add() {
return "display.jsp";
}
}
我面临的错误
HTTP Status 404 – Not Found
Type Status Report
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/10.0.10
给出输入后,错误出现,但错误显示。我还尝试了堆栈溢出时可用的其他解决方案,但没有一个有效。我使用的是 spring mvc 4 并使用了一些 youtube 视频。
解决方案
尝试在 html 表单的 action 属性中添加“/”
<form action="/add">
推荐阅读
- python - 如何减少导出到 Word 表格中的数据框中的行之间的行距?
- vba - 在 Word 文档中以编程方式导入宏
- reactjs - Next.js 重定向正则表达式不起作用
- r - svd(X) 中的错误:“x”中的值无限或缺失,但此处没有缺失值或无限值
- r - 是什么导致使用 cross() 函数在 filter() 中出现“找不到对象”错误?
- python - 如何为散景饼图添加额外的标签/图表名称
- python - 根据列名重新排序 Pandas 列
- c++ - 另一个类中的类对象的 C++ 析构函数
- javascript - JS Python与状态为0的ajax和flask交互
- permissions - 重命名 ABP 框架中的默认管理员角色