This has been the worst day ever. The network went down just long enough to interupt my nearly completed 8 hour download. I overwrote about 6000 words because of clumsy fingers. And now I've got a head cold. So, with all that in mind, please help me make some good of my day!
I've been struggling with this for weeks and keep putting it off. I'm trying to learn servlets from the "Head First Servlets and JSP" book but everytime I start coding whats in the book, I get errors. Here's what I've done this time:
I'm using Linux Fedora Core 3 and Java 1.5.0. I've uninstalled the latest version of tomcat (by deleting the /usr/local/tomcat directory). I've then installed a 5.0.xxx version in accordance with the preface to the book (version 5.0.28 to be precise). My $TOMCAT_HOME and $JAVA_HOME variables are set.
Then I start coding the examples on page 30 of the book and put them in the right directories (I've even figured out and fixed the error in the web.xml file in the xsi:schemaLocation attribute). I've compiled the .java file (no problems), put everything in the proper directories under webapps, and then started up tomcat (again no errors). I go to http://localhost:8080 and see the tomcat page a-ok! Then I go to http://localhost:8080/ch1/Serv1 and I get the following error:
Why can't it see my servlet? I've tried copying in some of the example servlets (which work fine in their own directory), changing the web.xml etc. to show where the new servlets are and what they're called, but they don't work in any folder I make under tomcat/webapps? I've also compiled other peoples servlet code and tried to see if that would work but no joy. I'm really at the end of my tether!
Is this an error with permissions or something? I must have tried this close to a hundred times in the last few months, different versions of tomcat, different servlet code, etc. etc. ! If anyone can tell me how to get a servlet working, or if you have any ideas what I'm doing wrong, or any ideas how I could begin to find out what I'm doing wrong, please reply!!!
(I'm not normally one for exclmation marks in posts, but I'm getting very frustrated )
Basically, what the error is saying is that your application does not exist in the $CATALINA_HOME/webapps directory.
1. Can you post the contents of your web.xml for the context /ch1? That would be a start.
2. Go to $CATALINA_HOME/webapps, verify that the WAR was deployed.
Joined: Dec 15, 2004
Here's my web.xml file:
It's saved in my $TOMCAT_HOME/webapps/ch1/WEB-INF/ directory and the class Ch1Servlet.class is saved in $TOMCAT_HOME/webapps/ch1/WEB-INF/classes. I've set the variable $TOMCAT_HOME to /usr/local/tomcat where I unzipped the tomcat binaries to (before I had it set as $CATALINA_HOME and still no joy, I switched to $TOMCAT_HOME because that's what the Head First book was using).
Correct the url-pattern(i.e. missing "n") and see if that fixes it.
Joined: Dec 15, 2004
I've corrected that in the web.xml file but I still get the same error. Maybe I'm doing something very basic wrong here, so I'll list the steps I take to deploy a servlet:
I shutdown tomcat I make a folder under $TOMCAT_HOME/webapps for my project ('ch1' in this case) In this folder I make a WEB-INF folder to store my web.xml file (prev post) In WEB-INF I have a 'classes' folder which holds my Ch1Servlet.class I restart tomcat and go to http://localhost/ch1/Serv1 I get a 404 I die a little inside
The Java class has been compiled using 'javac -classpath $TOMCAT_HOME/common/lib/servlet-api.jar Ch1Servlet.java'. It compiles fine, no errors.
Joined: Mar 19, 2002
From my understanding, you can't just create directories in the $CATALINA_HOME/webapps and expect TOMCAT to recognize them. You must deploy your web application in a WAR(web archive file).
You can use the jar command to create the WAR file, and then deploy(copy) the file in the webapps directory. TOMCAT will automatically(if haven't disable this functionality) recognize the file and expand the WAR and create the directory structure for you under webapps.
I would copy the contents of the folder "ch1" and/or then remove it from webapps, providing you have copies of your source code elsewhere.
Then create a WAR file of your web application. I usually create separate sub-directories of all my web applications. For example:
Tomcat will deploy your WAR under the context path "ch1". You can verify in the catalina.out.
I hope this helps.
Joined: Dec 15, 2004
Thanks craig, you've sorted me out! Post me a link to your amazon wishlist and I'll treat you to a CD or something. I can't tell you how much you've helped me out.
It turned out to be the stupidest problem. I think I've been making spelling mistakes in my web.xml file everytime I've copied it from the book (all 20 or so times I did it over the last eight weeks?!). When I examined the catalina.out log file I found tons of errors related to parsing the xml file (</servlet-class> vs. </serlvet-class>, spot the difference? took me a half hour). Once the web.xml file was corrected it ran like a dream (with the .war file or even if I just copied the files in as I had been doing).
I've been trying to get this working for the last two months and everytime I was hitting a 404 brick wall. Again, thanks a million Craig. Getting this working has been a weight off my shoulders (best day ever )
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Tomcat 5.0.28 won't play with my servlet =(