File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Simple Servlet problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Simple Servlet problem" Watch "Simple Servlet problem" New topic

Simple Servlet problem

John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
Hi, I have created a simple servlet and was able to deploy it to the Tomcat examples folder. Modified web.xml to contain the servlet and servlet-mapping tags for my HelloWorld servlet. I wanted to deploy it into another directoy so at the same level as examples forlder in Tomcat I created a folder called test and placed a web.xml plus the classes into that folder. The directory structure for my demo folder is


in my web.xml I have


but I cannot get to the servlet, I keep getting a HTTP 404, the requested resource (demo/servlet/HelloServlet) is not available.
the URL I am entering is http://localhost:8080/demo/servlet/HelloServlet

can anyone help??
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Is the HelloServlet class part of a package named "servlet"? If not, leave out the "servlet" from the URL and mapping.

In general you should avoid URLs that start with "servlet", because that looks like you might be using the InvokerServlet, which is not a good idea for the reasons explained on that page.
John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
I tried that and still I get a HTTP 404 error The requested resource (/HelloServlet) is not available.

Im a bit stumped as it works fine in the examples directory.
I must be doing something really stupid...
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13025
Im a bit stumped as it works fine in the examples directory.

Probably the web.xml for your example folder has the "invoker" servlet turned on. The invoker is able to look for servlet classes that are not in a formal package (the "default" package).

However, the normal JVM class loader can NOT cope with this. ALL classes used in servlets should be put in a package. Trust me - this forum is littered with threads where people found this out the hard way.

Your web.xml would then give a complete package for servlet-class and the compiled class would be located accordingly under WEB-INF/classes

More about the Invoker and how it leads programmers astray (same link as Ulf quoted.)

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63540

Is your web.xml in the WEB-INF folder? Your diagram seems to indicate not.

[Asking smart questions] [About Bear] [Books by Bear]
John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
yes it is. I got it working in the end by just steping through the example line by line. thanks for all the help...
subject: Simple Servlet problem
jQuery in Action, 3rd edition