My first servlet won't go

I'm doing a Grad Dip in IT, but it doesn't cover J2EE so I want to teach myself. I borrowed "Java for the Web with Servlets,JSP, and EJB" and thought, "Beaut, I'll just work my way through this and I'll have a good basic understanding of J2EE". Unfortunately, even though I have got Tomcat 4.1 working (I decided to use that since the book is 2002), for some unknown reason, when I try to call my servlet from Firefox (localhost:8080 etc) I get an error message: "The requested resource (/myApp/servlet/TestingServlet) is not available". This is the servlet code:

It is also worth pointing out that the example you are following is using the InvokerServlet.

When you write a Servlet, you need to map it to a 'name' on the server so that you can then ask for it by that name. This requires configuration in the web.xml file. The InvokerServlet short cuts this process by assuming that the servlet name is the same as the name used on the server. But there are several issues with using the InvokerServlet and it has fallen into disfavour - we don't recommend it, even for learning, and we have a page on the wiki devoted to it.

Anthony Denahy

Greenhorn

Posts: 7

posted 12 years ago

Thanks David. It is not an invoker issue - doesn't work either way. (?? P.S. I think I may have not completely uncommented the invoker) [ January 14, 2006: Message edited by: Anthony Denahy ]

Originally posted by Anthony Denahy: Thankyou for those suggestions Sara - I think I have all those things OK (sorry, I should have taken more effort to give the complete picture). What I'll try to do is use another simple beginners tutorial, with Tomcat 5.5, and see if it works then. Anthony

If you had all those things set up OK, then it would be working.

Where is your servlet's class file? What is the URL you are using to invoke the servlet? Did you explicitly map the servlet or are you relying on the InvokerServlet? If you did explicitly map it, post your servlet and servlet-mapping entries from your web.xml file.

Progress! I can get servlets to work in my "myApp" directory, however, at present I need to use the actual class name - for some reason I cannot use the name mapped in web.xml, and Invoker is not on (I think).

All fixed! The problem was in the Deployment Descriptor. The book I was using gave this as a suitable Descriptor for my first servlet:

but it seems that this is not enough - the following must be included also:

where the url-pattern can be a variety of things e.g. instead of "/servlet/Testing" I could use just "/Test", or if I wanted to be very tricky, even "/rabbit/wombat/walrus", in which case, if my TestingServlet.class was in the myApps/classes, then in my browser I would need to use the URL: http://localhost:8080/rabbit/wombat/walrus in order to run the servlet!