This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I can't get my first servlet to work on tomcat4. I have spent several days now pulling my hair out trying to configure my server.xml file and web.xml files etc. Still doesn't work. And, judging by what I have read in my tomcat book and in the tomcat documentation, I haven't make a mistake. Then I come accross this instruction provided by my hosting company: <instruction> Servlet Set Up - READ CAREFULLY To setup servlet, you need to configure servlet into the file web.xml which needs to be placed in /var/www/html/WEB-INF directory. www root directory or webapps:/var/www/htm Classes directory located in: /var/www/html/WEB-INF/Classes/ There you will need to upload your Java class file. Our default url-mapping for servlet is: /servlet/* To check servlet in your browser: www.mydomain.net/servlet/HelloWorld Jsp Files - Upload anywhere in /var/www/html DOUBLE CHECK: Double Check that that url-mapping for servlers is entered corectly in web.xml Double Check that Java class file is uploaded in the corect place. Without these two things your servlet will not work. </instruction> (The default context mapping for me is /var/www/html, not webapps by the way.) I understand what a deployment decriptor file is and how it is used in creating a servlet. I also know there is a "main" web.xml file in the conf directory. So what is the web.xml file they are refering to? I have already "configured servlet" (i think) in my main web.xml file by uncommenting the invoker element so that the /servlet/* mapping will work and I have created my own url-mapping in the web.xml file that is local to the servlet I am using. Still, nothing works. Are they talking about something different from what I have done? If you got this far thanks . I really need help here. Wasting sooo much time.
This "/servlet/" usage requires that the "Invoker" servlet be activated - this used to be the default Tomcat configuration when your book was written. But that is no longer true in Tomcat 4. See this FAQ discussion. for details. Bill
Joined: Feb 26, 2004
Thanks for the link. Still have the prob though. The invoker is commented out on thier system just like on my localhost setup. I wasn't planning on using the invoker for reasons like those mentioned in the link. I use a local web.xml file to define the context mapping for the servlet. Works fine on my localhost. Doesn't work when I deploy online though. Is the hosting company forcing me to use the Invoker? Why would they do that? And if they are why didn't they just un-comment it themselves? I wrote them an email to this effect and I was told to make a local web.xml file that included this: <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/servlet/HelloServlet</url-pattern> </servlet-mapping> If the whole point in using the Invoker is to allow you to deploy servlets that are not mapped then why tell me to include a mapping? Wouldn't this mapping supercede the mapping provided by the Invoker? And if so, why does it have to start with /servlet/? At this point I would be willing to accept that I have to use a local web.xml file that always starts it's mapping with /servlet/ and not know why , but doing that doesn't work either...
Author and all-around good cowpoke
Joined: Mar 22, 2000
Well, I'm mystified - if their default mapping uses /servlet/* that sure sounds like the invoker is turned on in the default web.xml. I guess I don't understand the environment you are working in. Exactly how much control do you have over the host machine? I would be really supprised if they let you fiddle with server.xml or the default web.xml. Bill
Okay, first of all, for a simple shared web hosting environment (most inexpensive hosting) you don't want to mess with server.xml unless you know what you are doing. Likewise, don't mess with the default web.xml file unless you really have to. I have been doing this for about five years and have never needed to edit the default web.xml file. Edit your web.xml file found at WEB-INF/web.xml. The /servlet/* requirement that your hosting has is most likely due to security or Apache URL mapping requirements (they may have Apache handling the HTML and overall routing). Hope this helps.
- Chris Stehno, SCPJ
Joined: Feb 26, 2004
have never needed to edit the default web.xml file.
I actually did change the main web.xml file once to add a MIME type (for the flash remoting AMF protocol).
Apache URL mapping
That's probably it...I didn't even think about apache. I have full control over tomcat but not over apache. You'll note that in the first message it says
configure servlet into the file web.xml which needs to be placed in /var/www/html/WEB-INF directory
The host's default setup has the webapps directry set to /var/www/html/ and not the <cataline-home>/webapps directory. I was thinking this might be the key to the problem. They are telling me to create a WEB-INF directory in my /var/www/html/ (webapps for most people) directory and place a web.xml file in it to "set-up servlet". Unfortunately they made the assumption that this information alone was enough to get me going. What would a web.xml file would do or consist of to "set-up servlet" from there? I should also mention that I am still confused as to what they mean by "set-up servlet". I mean, if I have to configure a web.xml file in that directory to set up servlet and it has something to do with apache too then my weekend is gone . There is nothing that I have found that talks about a configuration like this. Another prob is that my budget hosting includes a budget location. They are in Norway and I'm in NYC. So any correspondance I have with them takes at least 12 hours cause I sleep when they are awake. Thanks for the help so far. It's taken me a while just to define what the problem is.