File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet 404 error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet 404 error" Watch "Servlet 404 error" New topic

Servlet 404 error

lakshmanan anand

Joined: Jan 13, 2009
Posts: 22

I just got the book "Head first Servlets and JSP " book and i am implementing the example given in the first chapter.
I am using windows XP.

  • I wrote a servlet class and it compiled without errors.
  • I used classpath variable for servlet-api.jar to compile the class

  • I created the directory ch1 and put it inside the webapps directory under tomcat. My directory structure is ch1->WEB-INF->classes->Ch1Servlet.class

    my Deployment Desciptor (web.xml ) file is

    I typed http://localhost:8080/ch1/Serv1 as the URL. But still i get 404 error. Please help
    William Brogden
    Author and all-around good cowpoke

    Joined: Mar 22, 2000
    Posts: 13037
    Your problem is due to the servlet class not being in a package.

    ALL classes used in servlets should be in a package and stored under classes according to the package.

    Older versions of Tomcat and older books depended on the "invoker" servlet to find classes not in a package - this was a very very very bad idea and was abandoned years ago. The original designers thought it would make things easier for beginners but it has caused untold trouble.

    See this ranch FAQ for the ugly details.

    I agree. Here's the link:
    subject: Servlet 404 error
    It's not a secret anymore!