HTTP 状态 404 - 在具有 Tomcat 的 Eclipse 上(没有生成 web.xml)

HTTP Status 404 - on Eclipse with Tomcat (with no generated web.xml)

我正在使用 Eclipse 和 Tomcat 9.0 动态 Web 模块 4.0 开发一个示例,但没有生成 web.xml 部署。

项目目录如下:

其中 reverse.java 是获取输入参数并将其发送回输出页面的 servlet。 出于某种原因,在我点击提交按钮后,无法访问“/reverse”servlet,并且 tomcat 提示 HTTP Status 404 - Not Found 页面。我做错了什么?

点击 inputForm.jsp 页面上的提交按钮后,出现错误:

Type Status Report

Message /reverse

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

URL 输入时调用了提交 input = "abcd": http://localhost:8080/reverse?input=abcd

我做错了什么?谢谢。

如果您没有明确设置 set context root,默认情况下会将其设置为与您的项目同名。如果您的项目名称是 "bla",那么调用 servlet 的 URL 应该如下所示:http://localhost:8080/bla/reverse.