After days of torment of trying to run my HelloWorldServlet I managed to run my servlet via the backdoor. I am using Tomcat so I naturally placed my servlet in the ROOT\WEB-INF\classes - which did not work. I then placed the same HelloWorldServlet in the examples\WEB-INF\classes and accessed via a modified index.html page in the examples directory. It worked I am unable to figure why this would be the case. It is obivous that the problem was with where the file was placed. Could anyone shed some light on this for me thanks Oh and thank you to everyone who replied to my last post. david
The best thing I can recommend is for you to download and read the servlet specification. Of particular interest in this case, is SRV.9.1 - SRV.9.5, plus SRV.11
This give the 'official' view of what a web application is, the directory structure of a web app, and how servlets 'map' to URLs
The other really great resource is the very large comments that are to be found inside Tomcat's default web.xml at CATALINA_HOME/conf/web.xml and Tomcat's documentation for server.xml, which is how you configure web applications in Tomcat
As a (very) high overview, you want to map your servlet classes to request URLs (in web.xml inside your webapp), and then register your webapp with Tomcat (in server.xml).
Many tutorials (and some of them have really great other information, so it's hard to dismiss them) still use ROOT directory of Tomcat and use the 'lazy' mapping provided by 'most' (but not all) servlet containers... ie: "just place your servlet class here and call it like http://myserver.com/servlet/servlet.class.name"
While not 'wrong', this is not the best practice.
In fact, if you read web.xml I mentioned to you above, you'll see how Tomcat provides the /servlet/* pattern matching. It's in there in the comments.
What you'd want to do is create your own, web-application specific version of the web.xml file, which maps specific servlets to specific URLs. Then Tomcat can combine the webapplication name plus mapping provided in web.xml to serve the correct servlet.
Hi David Saw your posts regarding your Tomcat/Servlet troubles. What version of Tomcat are you using ? this makes a diff., especially concerning the problems you describe. I can recommend the www.coreservlets.com site. Has exellent info on basic Tomcat/Servlet/JSP configuration for major Tomcat versions. And hey - let people know of you progress - preferably in this thread. Martin
David the response to your problem with your serlvet resides in the web.xml File . first you have to know a lttle of XML (Extended Markup Language ) to understand it; but is quite simple as html does ..
the web.xml is a place where you put and describe each servlet in your web application so...
look for the <Servlet Tag .. and yo will realize that this tag gives a servlet a name; and also search for the ... <servlet-mapping Tag and it maps . (relates) the servlet (defined previously) to the URL in the web application ..
Thank you for your help. I have got it working but I think everyone is right, I need to read up on the web.xml file. I am only new to this and I am working out of a book and that was the first stage - setting up and testingjsp and servlets. I have uni exams in a couple of weeks so after that I will get back into it.
Thanks again for your help it is much appreciated. David