Meaningless Drivel is fun!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Unable to run Servlets using Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Unable to run Servlets using Tomcat" Watch "Unable to run Servlets using Tomcat" New topic
Author

Unable to run Servlets using Tomcat

Benny Brown
Greenhorn

Joined: Sep 25, 2004
Posts: 7
On page 81 in Head First Servlet & JSP i've been trying to get my Beer app working on Tomcat. The form.html page is displayed if I put the Beer-v1 directory inside the webapps\ROOT directory. However, it's not displayed when put in webapps directory. As for the BeerSelect servlet, it does not execute no matter which of the two directories i put the Beer-v1 directory.

Does anyone have a suggestion of what might be wrong?

I've allready passed the Programmer Certification. Thanks to Sierra and Bates! Keep the books comming

Kind regards
Benny
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy!
Hmmm... not quite sure what could be the problem. For your servlet, be certain that you restart Tomcat before trying to access it. Also, double and triple-check the name of the directory and what you put in the browser bar, and what you put in the DD. There are so many places where the tiniest thing can stop it from working...

I assume you're using Tomcat 5, so the best that I can say is to keep looking at all the pieces and make sure everything is spelled correctly, etc.

Please let us know how it is going, one way or the other. We're determined to make sure everybody gets it running eventually, but as far as we've seen, everything in the tutorial does work exactly as it is in the book (with the exception of people having to adjust the command-line syntax to match their specific shell).

good luck, hang in there!
-Kathy
Benny Brown
Greenhorn

Joined: Sep 25, 2004
Posts: 7
Thank you for your quick response Kathy!

I've double checked everything in my web.xml file, and also tried several different url-patterns, but without success.

A couple of questions come to mind:
  • Should my Beer-v1 directory be placed inside the webapps or the webapps/ROOT directory? Using http://localhost:8080/Beer-v1/form.html only loads the page when my Beer-v1 directory is placed inside ROOT.
  • Could it be something wrong with my tomcat installation?

  • I run Tomcat 5.0.27 as a Windows service.
    Environment variables:
    JAVA_HOME=C:\j2sdk1.4.2_05
    CLASSPATH=C:\j2sdk1.4.2_05\jre\lib\rt.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;classes;.;TOMCATHOME=C:\Program Files\Apache Software Foundation\Tomcat 5.0


    I hope someone spots an error here...

    Thanks
    Benny

    [ September 26, 2004: Message edited by: Benny Brown ]
    [ September 26, 2004: Message edited by: Benny Brown ]
    Andy Chang
    Greenhorn

    Joined: Mar 24, 2004
    Posts: 5
    Should my Beer-v1 directory be placed inside the webapps or the webapps/ROOT directory? Using http://localhost:8080/Beer-v1/form.html only loads the page when my Beer-v1 directory is placed inside ROOT.

    Either Beer-vi directory be placed inside the webapps or the webapps/ROOT directory is fine. But did you create appropriate WEB-INF directory and web.xml file in the Beer-v1 directory when you placed inside the webapps?
    Good luck!
    Me
    Ranch Hand

    Joined: Dec 01, 2003
    Posts: 51
    Here are some of the suggestions.

    As mentined earlier
    Beer-v1 directory can be placed in any of the two directories webapps/ROOT Or webapps

    Let us say that you are putting it in webapps directory you should have following directories in webapps

    Beer-v1
    Beer-v1/WEB-INF
    Beer-v1/WEB-INF/classes

    and
    web.xml goes to Beer-v1/WEB-INF directories and all of the classes (along with the package directory structure) go to Beer-v1/WEB-INF/classes

    Sometimes your web.xml has some typo so everything is OK but since web.xml is no good your application is not deployed. So look for such error message in Tomcat window.

    Tomcat must be restarted for the FIRST time you deploy application.
    Once deployed you can go to
    http://localhost:YOUR_PORT_HERE/manager/html

    to reload your application without restarting Tomcat


    Hope this helps. Let me know if you still can not get through
    Kathy Sierra
    Cowgirl and Author
    Ranch Hand

    Joined: Oct 10, 2002
    Posts: 1572
    Howdy -- you really should put "Beer-v1" inside the webapps directory, not at the tomcat root!

    You want to make sure that everything is organized correctly. It's VERY tricky to make sure that everything everywhere is spelled absolutely perfectly, or it won't work.

    Remember, in the development environment in the book we named the directory "beerV1", and in the deployment directory it is named "Beer-v1" (we wanted to make sure they were different so that you wouldn't mistake one for the other), so check the capitalization and spelling carefully. The way it is laid out in the chapter will definitely work assuming everything is setup exactly as it is in the book, and if you get tomcat working, then you shouldn't have to do any additional configuration.

    The only issues you will have are for compiling, where you need to adjust your shell syntax to match your specific shell, and of course your environment variables.

    It is NOT trivial to get this working, because a 404 error isn't exactly helpful in pointing out what could be wrong, but I urge you to follow the tutorial instructions in the book EXACTLY as they are, or else it will be even harder to troubleshoot, and putting things in ROOT is not a good solution.

    Try not to get frustrated. I think the first time I tried to deploy a webpp in Tomcat it took me about two days to get everything exactly right. But if you use an ANT script, for example, that does it all for you (which is great once you really understand what its doing and you're in real world development), you won't be nearly as clear about how it is all supposed to be setup. So for both the exam and your ability to learn it, you really should do this all by hand until you get it right.

    Hang in there... it could be worse It could be EJB...

    cheers,
    Kathy
    Benny Brown
    Greenhorn

    Joined: Sep 25, 2004
    Posts: 7
    Hello everybody.

    I'm up and running

    It turned out to be an error in my web.xml

    my </url-pattern> was spelled </utl-pattern>.

    A little misstake but with huge implications!

    Thanks to all of you trying to help

    regards
    Benny
    Steven Hoodless
    Ranch Hand

    Joined: Mar 23, 2004
    Posts: 64
    I found the following article useful to set up Tomcat. When I first downloaded Tomcat I assumed you only had to start it up not configure it yourself.

    http://www.coreservlets.com/Apache-Tomcat-Tutorial/#Summary

    Steven


    SCJP, SCJD, SCWCD.
    Tomasz Luchowski
    Greenhorn

    Joined: Sep 16, 2004
    Posts: 15
    I was bitten by what seems to be the same problem today. When I tried to access http://localhost:8080/beer-v1/form.html I got the following error:

    HTTP Status 404 - /beer-v1/form.html

    type Status report

    message /beer-v1/form.html

    description The requested resource (/beer-v1/form.html) is not available.
    Apache Tomcat/5.0.28


    Spelling "Beer-v1" with proper casting (capital B) solved the problem for me.

    Hope this helps,
    Tomasz


    Tomasz Luchowski<br />SCJP, SCBCD, SCWCD, SCEA part 1
    Sandya Bhaskara
    Ranch Hand

    Joined: Aug 20, 2004
    Posts: 73
    even i have the same pblm...couldn't run the form.html using tomcat...i'm getting 404error..


    HTTP Status 404 - /BeerProject/form.html

    --------------------------------------------------------------------------------

    type Status report

    message /BeerProject/form.html

    description The requested resource (/BeerProject/form.html) is not available.


    --------------------------------------------------------------------------------
    not able to figure outwhat went wrong


    Sandy<br />SCJP1.4 SCWCD1.4<br />SCBCD(preparing)
    Sandya Bhaskara
    Ranch Hand

    Joined: Aug 20, 2004
    Posts: 73
    even i have the same pblm...couldn't run the form.html using tomcat...i'm getting 404error..


    HTTP Status 404 - /BeerProject/form.html

    --------------------------------------------------------------------------------

    type Status report

    message /BeerProject/form.html

    description The requested resource (/BeerProject/form.html) is not available.


    --------------------------------------------------------------------------------
    not able to figure outwhat went wrong
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Unable to run Servlets using Tomcat