HTTP状态404 - 在带有Tomcat的Eclipse上

use*_*184 10 eclipse servlets tomcat7

我只是想用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>
Run Code Online (Sandbox Code Playgroud)

Har*_*hra 21

我看到了你的链接.

什么时候运行任何动态Web项目.默认情况下,Servlet容器(在本例中为Tomcat)搜索wel-come列表中指定的文件.检查你的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>
Run Code Online (Sandbox Code Playgroud)

您尚未从上述任何列表中创建文件.所以,跑步

http://localhost:8080/TEST2 会给你404错误.

而是运行:http://localhost:8080/TEST2/HelloSerlvet将调用您创建的servlet.

编辑:检查eclipse的项目菜单并验证"自动构建"并检查Servlet容器是否正在运行(http://localhost:8080).

编辑2:右键单击项目 - >属性,选择Java构建路径 - >源选项卡 - >更改默认输出文件夹.创建/WEB-INF/classes/WebContent(默认情况下在eclipse中)


小智 7

这是基于Hardik Mishra的答案,其中有一些亮点:1.从文件资源管理器(而不是Eclipse),在/ WebContent下手动创建"/ WEB-INF/classes"2.右键单击项目 - >属性,选择Java构建路径 - >源选项卡 - >将默认输出文件夹更改为您刚刚创建的文件夹.3.转到文件资源管理器,而不是Eclipse,因为Eclipse"项目资源管理器"可能有一些不显示classes文件夹的过滤器.您应该看到在此目录下编译的.class文件

尝试再次测试它.如果它不起作用,重启Eclipse一次,然后它应该工作.