Could someone please give me a little insight into how I get my servlet to run I have written a servlet and much to my astonishment it compiles!! Now I have put the class file in ROOT\WEB-INF\hello.class but when I user the URL http://localhost/servlet/hello I get an error message. Do I have to edit the web.xml file. If so you could someone please post the code. thanks david
You should place your servlet in: 'ROOT\WEB-INF\classes\hello.class' and put these lines in 'web.xml' <servlet> <servlet-name>hello</servlet-name> <servlet-class>hello</servlet-class> </servlet> Rene [ October 09, 2002: Message edited by: Rene Larsen ]
I've been wrestling with the same issue in Tomcat 4.1. Supposedly, if one creates a new context (directory within /webapps), on Tomcat startup, that context will get picked up, and if there's no web.xml file within its WEB-INF directory, then the default web.xml will be used, which should allow us to access our servlets using a URL like: http://host/context/servlet/[package info.]servletName without muddling with web.xml files or server.xml files. Practically speaking, I've had to have a web.xml file in my local context area with both a <servlet> definition and a <servlet-mapping> definition. So, my web.xml for a HelloServlet servlet looks like this:
This means, though, that any request to my servletConnect context (even static HTML files within the context) maps to my servlet. I could update the URL pattern to be more specific, but am not concerned about it for my test purposes.
Fist .. in old web server ( with servlet usage) there used to be a servlet directory where all the servlets ( as cgi used to ) shoud be putted ..
a special directory where all the servlets should go . and of course the same is Servlet.. later with the comming of the "Application Servers" there's no such directory .. there's sometig called servlet context . and there's a new role called WEB Application . the web application consists in a structure you should follow to make your servlets and your whole application to work .
the structure ( you should create) is the following . WEB-INF |______classes "CASE SESITIVE!" iside of WEB-INF directory there should be a web.xml . wich maps . URL's to your servlet classes . wich are putted under the classes directory
if you use packages you sould also use subdirectories as you use in java .. in older posts they explain the web.xml contents .
so put your files under the correct structure and enjoy your sevlets .. Grettings . .
PD. Application servers are the context creators for your servlet. yo could use tomcat it's free and comes with some web applications you coudl use as example