简体   繁体   English

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

[英]HTTP Status 404 - on Eclipse with Tomcat

I am trying just to run a servlet on my local Tomcat with Eclipse.我正在尝试使用 Eclipse 在我的本地 Tomcat 上运行一个 servlet。

But I keep getting this error and do not have any idea what to do differently.但是我不断收到此错误,并且不知道该怎么做。

I actually recorded it here : http://www.screenr.com/ZyD8我实际上记录在这里: http : //www.screenr.com/ZyD8

Many thanks!非常感谢!

Also I changed the web.xml to this:我也将 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>

I have seen your link. 我看到了你的链接。

When ever you run any dynamic web project. 什么时候运行任何动态Web项目。 By default Servlet container (which is Tomcat in this case) searches for files specified in wel-come list. 默认情况下, Servlet容器(在本例中为Tomcat)搜索wel-come列表中指定的文件。 Check your web.xml , it should contains entry like 检查你的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>

You haven't created file from any of the above list. 您尚未从上述任何列表中创建文件。 So, running 所以,跑步

http://localhost:8080/TEST2 will give you 404 error. http://localhost:8080/TEST2会给你404错误。

Rather run : http://localhost:8080/TEST2/HelloSerlvet will invoke the servlet which you have created. 而是运行: http://localhost:8080/TEST2/HelloSerlvet将调用您创建的servlet。

Edit: Check Project Menu of eclipse and verify "Build Automatically" is checked and Servlet container is running ( http://localhost:8080 ). 编辑:检查eclipse的项目菜单并验证“自动构建”并检查Servlet容器是否正在运行( http://localhost:8080 )。

Edit 2: Right Click Project --> Properties, Select Java Build Path --> source Tab --> Change Default output folder. 编辑2:右键单击项目 - >属性,选择Java构建路径 - >源选项卡 - >更改默认输出文件夹。 Create /WEB-INF/classes under /WebContent (default in eclipse) /WebContent下创建/WEB-INF/classes (在eclipse中默认)

This is based on the answer from Hardik Mishra with some highlights: 1. From the file explorer (not from Eclipse), Manually create the "/WEB-INF/classes" under /WebContent 2. Right Click Project --> Properties, Select Java Build Path --> source Tab --> Change Default output folder to the folder you just created above. 这是基于Hardik Mishra的答案,其中有一些亮点:1。从文件资源管理器(而不是Eclipse),在/ WebContent下手动创建“/ WEB-INF / classes”2。右键单击项目 - >属性,选择Java构建路径 - >源选项卡 - >将默认输出文件夹更改为您刚刚创建的文件夹。 3. go to the file explorer, not from Eclipse, since the Eclipse "project Explorer" may have some filters that doesnot show the classes folder. 3.转到文件资源管理器,而不是Eclipse,因为Eclipse“项目资源管理器”可能有一些不显示classes文件夹的过滤器。 You should see the .class files compiled under this directory 您应该看到在此目录下编译的.class文件

Try to test it again. 尝试再次测试它。 If it does not work, restart Eclipse for one time and then it should work. 如果它不起作用,重启Eclipse一次,然后它应该工作。

I have been seeing these types of issue for quite sometime and have seen multiple solutions which work for some and rest still face the same issue. 我已经看到这些类型的问题很长一段时间了,已经看到多种解决方案适用于某些人,其余的仍然面临同样的问题。

One of the simple solution is traverse to the .java/.jsp/etc., right click and select run from server option. 其中一个简单的解决方案是遍历.java / .jsp / etc.,右键单击并选择从服务器选项运行。

I found this solution to be simple yet effective way of running. 我发现这个解决方案是简单而有效的运行方式。

path Java Resource->src->->example.java-->right click-->run as-->run on server. path Java Resource-> src - > - > example.java - >右键单击 - >运行为 - >在服务器上运行。

Even after this also you can face few issues like port 8005 not available, please follow the below link to clean out your current Apache setting and re-setting the same. 即使在此之后,您也可能遇到一些问题,例如端口8005不可用,请按照以下链接清除您当前的Apache设置并重新设置相同的设置。

TOMCAT - HTTP Status 404 TOMCAT - HTTP状态404

Deployment error:Starting of Tomcat failed, the server port 8080 is already in use 部署错误:Tomcat启动失败,服务器端口8080已在使用中

Hope this finding was helpful. 希望这个发现很有帮助。

Normally, when you modify the web.xml file, you should "clean" Tomcat. 通常,在修改web.xml文件时,应该“清理”Tomcat。 Just right-click on Tomcat in Eclipse and clean. 只需右键单击Eclipse中的Tomcat并清理即可。 Do same for project. 为项目做同样的事情。 You may also stop Tomcat, remove the app from Tomcat (right-click on app under Tomcat and remove) and then add it back. 您也可以停止Tomcat,从Tomcat中删除应用程序(右键单击Tomcat下的应用程序并删除),然后将其添加回来。 Restart Tomcat. 重启Tomcat。

I am gonna divide this problem in two scenarios:我要把这个问题分为两种情况:

scenario 1: you are trying to run/execute html/jsp file but getting this error.场景 1:您正在尝试运行/执行 html/jsp 文件但收到此错误。

scenario 2: you have successfully executed jsp/html file but it is not executing next servlet file.场景 2:您已经成功执行了 jsp/html 文件,但它没有执行下一个 servlet 文件。 example: there is jsp submit form in webcontent/webapp, it is getting executed but after filling and submitting form you are getting this error.示例:在 webcontent/webapp 中有 jsp 提交表单,它正在执行,但在填写并提交表单后,您收到此错误。

Scenario 1:场景一:

  1. Make sure that your jsp/html file are in webcontent/webapp folder that you created at the time of project creation.确保您的 jsp/html 文件位于您在项目创建时创建的 webcontent/webapp 文件夹中。

  2. check web.xml file where content should be like this:检查web.xml文件,其中的内容应该是这样的:

    在此处输入图片说明

  3. try changing tomcat server version.尝试更改 tomcat 服务器版本。

Scenario 2:场景2:

  1. at this level your main culprit is web.xml file where you have to check Servlet mapping thoroughly or add webservlet annotation at file level.在这个级别,您的主要罪魁祸首是 web.xml 文件,您必须彻底检查 Servlet 映射或在文件级别添加 webservlet 注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM