Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

servlets - HTTP Status 404 - on Eclipse with Tomcat

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...