HTTP Status 404 - on Eclipse with Tomcat
Asked Answered
A

5

11

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

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

Many thanks!

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>
Avogadro answered 2/7, 2012 at 8:20 Comment(2)
Does Servlet having packages, if yes then write fully qualified class name in web.xmlSamson
it is in "default package". But even if I create it in a package "test.servlet" and the put "test.servlet.HelloServlet" as the class name in web.xml it gives the same errorAvogadro
S
21

I have seen your link.

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 will give you 404 error.

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

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

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)

Samson answered 2/7, 2012 at 8:33 Comment(10)
please see my attached web.xml - when I type "localhost:8080/TEST2/HelloSerlvet" it gives same error. I think the class does not get deployed at all in the correct location, but I do not know what to do?Avogadro
Sorry, but I tried everything and still did not work. What do I have to put as Buildpath on top under "source folders on build path" and what should I put under "Default Output FOlder". Should I check the "Allow output folders as source folders" ?Avogadro
Please read carefully. I have mentioned to create new folder. in Edit 2Samson
yes I have also created the classes folder -> I have added the screen on the topAvogadro
Also whenever I check my classes folder in the Terminal under /Library/Tomcat/test2/web-inf/classes it is empty. Shouldn't the HelloServlet class be deployed there or did I misunderstand?Avogadro
Yes, .class file should be thereSamson
What could be wrong - since it is never there - I tried for the last couple of days without successAvogadro
Try Project Menu -> Build All which should create .class file under TEST2/WebContent/WEB-INF/classesSamson
no for some reason in my case it doesn't - And I am really without any new ideas....Avogadro
let us continue this discussion in chatSamson
K
7

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. 3. go to the file explorer, not from Eclipse, since the Eclipse "project Explorer" may have some filters that doesnot show the classes folder. You should see the .class files compiled under this directory

Try to test it again. If it does not work, restart Eclipse for one time and then it should work.

Konya answered 9/8, 2013 at 21:42 Comment(0)
B
4

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.

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.

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.

TOMCAT - HTTP Status 404

Deployment error:Starting of Tomcat failed, the server port 8080 is already in use

Hope this finding was helpful.

Breastfeed answered 22/5, 2014 at 9:41 Comment(0)
V
0

Normally, when you modify the web.xml file, you should "clean" Tomcat. Just right-click on Tomcat in Eclipse and clean. 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. Restart Tomcat.

Velda answered 30/1, 2016 at 3:22 Comment(0)
R
0

I am gonna divide this problem in two scenarios:

scenario 1: you are trying to run/execute html/jsp file but getting this error.

scenario 2: you have successfully executed jsp/html file but it is not executing next servlet file. example: there is jsp submit form in webcontent/webapp, it is getting executed but after filling and submitting form you are getting this error.

Scenario 1:

  1. Make sure that your jsp/html file are in webcontent/webapp folder that you created at the time of project creation.

  2. check web.xml file where content should be like this:

    enter image description here

  3. try changing tomcat server version.

Scenario 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.
Rachaba answered 8/11, 2021 at 11:19 Comment(1)
Welcome to Stack Overflow! Please avoid posting images (or worse, links to images) of code or errors. Anything text-based (code and errors) should be posted as text directly in the question itself and formatted properly as a minimal reproducible example. You can get more formatting help here. You can also read about why you shouldn't post images/links of code.Rh

© 2022 - 2024 — McMap. All rights reserved.