我正在尝试使用 Eclipse 在我的本地 Tomcat 上运行一个 servlet。
但是我不断收到此错误,并且不知道该怎么做。
我实际上记录在这里:http://www.screenr.com/ZyD8
非常感谢!
我也将 web.xml 更改为:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" >
<display-name>
TEST3
</display-name>
<welcome-file-list>
<welcome-file>
TEST3
</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>
helloServlet
</servlet-name>
<servlet-class>
HelloServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
helloServlet
</servlet-name>
<url-pattern>
/hello
</url-pattern>
</servlet-mapping>
</web-app>
最佳答案
我看过你的链接。
当您运行任何动态 Web 项目时。默认 Servlet
容器(在本例中为 Tomcat)搜索在欢迎列表中指定的文件。检查您的 web.xml
,它应该包含像这样的条目
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
您尚未从上述任何列表中创建文件。所以,运行
http://localhost:8080/TEST2
会给你 404 错误。而是运行:
http://localhost:8080/TEST2/HelloSerlvet
将调用您创建的 servlet。编辑:检查 eclipse 的项目菜单并验证“自动构建”已选中并且 Servlet 容器正在运行(
http://localhost:8080
)。编辑 2:右键单击项目 --> 属性,选择 Java 构建路径 --> 源选项卡 --> 更改默认输出文件夹。创建
/WEB-INF/classes
下 /WebContent
(Eclipse 中的默认设置)
关于eclipse - HTTP 状态 404 - 在带有 Tomcat 的 Eclipse 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11290029/