HTTP 状态 404 - 在带有 Tomcat 的 Eclipse 上 [英] HTTP Status 404 - on Eclipse with Tomcat

查看:37
本文介绍了HTTP 状态 404 - 在带有 Tomcat 的 Eclipse 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Eclipse 在我的本地 Tomcat 上运行一个 servlet.

I am trying just to run a servlet on my local Tomcat with Eclipse.

但我不断收到此错误,并且不知道该怎么做.

我实际上是在这里记录的:http://www.screenr.com/ZyD8

I actually recorded it here : http://www.screenr.com/ZyD8

非常感谢!

我也将 web.xml 更改为:

Also I changed the web.xml to this:

      <?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,它应该包含像

When ever you run any dynamic web project. By default Servlet container (which is Tomcat in this case) searches for files specified in wel-come list. Check your web.xml, it should contains entry like

<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>

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

You haven't created file from any of the above list. So, running

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

http://localhost:8080/TEST2 will give you 404 error.

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

Rather run : http://localhost:8080/TEST2/HelloSerlvet will invoke the servlet which you have created.

检查 Eclipse 的项目菜单并验证自动构建"已选中且 Servlet 容器正在运行(http://localhost:8080).

Check Project Menu of eclipse and verify "Build Automatically" is checked and Servlet container is running (http://localhost:8080).

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

Edit 2: Right Click Project --> Properties, Select Java Build Path --> source Tab --> Change Default output folder. Create /WEB-INF/classes under /WebContent (default in eclipse)

这篇关于HTTP 状态 404 - 在带有 Tomcat 的 Eclipse 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆