• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pulling my hair out over Tomcat servlets

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. I know its been talked about many times already but Ive read all the discussions and any tutorials I can find and still no joy with Tomcat.
I can see all examples.
I can see the HelloServlet and the HelloServlet2 from the install_dir/webapps/ROOT directory.
I can see JSPs and HTMLs in folders I create under the webapps directory.
I can't see any servlets or beans I have created myself or premade ones from any tutorials including the ones provided by wrox for the Java Serving Programming book.
I carefully followed the steps provided by this in-depth tutorial:
http://www.onjava.com/pub/a/onjava/2001/04/19/tomcat.html
and get this message:
Apache Tomcat/4.0.3 - HTTP Status 404 - /onJava/servlet/com.onjava.login
type Status report
message /onJava/servlet/com.onjava.login
description The requested resource (/onJava/servlet/com.onjava.login) is not available.
And any javabeans I create cannot be instantiated and throw an exception stating so. What the hell is wrong with me?!
Any light would be delightful.
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the article that I presented at JavaOne last year. It is available on my website at www.samjdalton.com under the conferences section. This shows step by step how to deploy a web application (including servlets, jsps and tag libs) to tomcat.
You might also check out Professional Java Servlets from Wrox press. this has a great chapter on deployment (i should know I wrote it )
S
 
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for you help Sam. I checked out your website but could not see anything different to what I have done. The only thing I havent tried is making the app into a war file. Just the same, I will try out your source code and see how it goes. I get back to you then. Not much hope for this though after three days of copy, compile, deploy, disapoint; copy, compile, deploy, disapoint; copy, compile, deploy, disapoint;...
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How have you set up a web.xml file for your application? Incorrect web.xml is frequently a cause of problems like this.
You should certainly have a copy of the servlet API - the last word in configuration requirements - download from java.sun.com
Bill
 
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi There. Yes i've tried quite a few web.xml files. I also have the Servlet API. Still no go. I'm starting to think maybe I should download a different version of Tomcat. I think mine is 4.0.3 but I will have to go home and check. Anyone else had a problem with this version... assuming that is what it is.
 
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will post the xml file and other details this afternoon (Aussie time) when I get home. Probably a bit much to expect a diagnosis with the info I've provided.
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with William, I had the same type of problems you are getting when I first deployed a web app, following tutorials and books step-by-step, and it ended up being my web.xml file. It wasn't until I copied web.xml from the ROOT/WEB-INF directory that I was able to get the app to be recognized and work right.
Try doing that, also move your login servlet to the base (don't use the package stuff), just to see if you can get that to work. If that works, then you know you have a package path problem, also. Just a suggestion.
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi - I think it has to do with:
action="servlet/com.onjava.login"
coded in login.jsp.
I think it should be:
action="com.onjava.login"
without the 'servlet' part.
Just a WAG, have not tested.
Regards, Guy
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope - I was wrong, the 'servlet' part does need to be there.
But am , cause it runs on my system.
(Which I guess I should say is TC 4.01, I have 4.03 DL'd, but not installed).
Guy
[ March 13, 2002: Message edited by: Guy Allard ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Jason, the problem might be with the web.xml . <servlet-class> packagename.servletclass <servlet-class>
Also try doing it without the packages.
Hope
 
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am hoping it is the web.xml file. I really am. But i copied it directly from the tutorial linked in my original post. Guy seems to have got the thing working though. Did you copy all files including the web.xml file directly from the web page? If so, I think that rules out the web.xml. I will try it out without packages and with the default web.xml included in ROOT when I get home and let you know how I get on.
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CT - Well, I really 'cheated'. Here is what I did.
I have an existing webapp: gma
I cut and pasted login.jsp to the gma root.
I have an existing 'com/guyallard' set of driectories, so I cut and paste login.java to:
..../gma/WEB-INF/classes/com/guyallard
In login.jsp I change action= to:
servlet/com.guyallard.login
In login.java I change the package name to :
com.guyallard
I 'cd' to that directory and run a compile from the command line.
I stop/start TC.
When I do:
http://localhost:8080/gma/login.jsp
I get a resource not found for welcome.jsp, and I expect this because I did not load it down from the web! However I do get to the servlet (login.java->class), which you are not!
There is of course an existing web.xml for this webapp. I did not add any entries for either the jsp or the servlet involved in this test. There are entries for other servlets/JSPs I am working on.
So .... where does this leave us?
I don't know, will think on it.
Regards, Guy
Later - Incidentally, I also make no changes to server.xml. TC automatically recognizes properly structured directories under $CATALINA_HOME/webapps.
[ March 13, 2002: Message edited by: Guy Allard ]
 
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to be sure I should make sure I've got the basics right (I'm sure its going to be something really silly!)
I have put my application root directory (onJava in this example) in the TOMCAT_HOME/webapps directory with the appropriate structure underneath. Tell me. Is this correct?
 
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. I'm at home now. Heres my web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN' 'http://java.sun.com/j2ee/dtds/web-app_2.2.dtd'>
<web-app>
<display-name>Forum</display-name>
<description>A Forum for anything</description>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.onjava.login</servlet-class>
</servlet>
</web-app>
Hopefully there is something wrong there.
Here is my directory structure (all files copied from the link in 1st post:
c:\Program Files\Apache Tomcat 4.0\webapps\onJava
>login.jsp
>Welcome.jsp
>WEB-INF
>web.xml (as above)
>classes
>com
>onJava
>login.class (package com.java)
I made this adjustment to server.xml:
<Context path="/onJava" docBase="onJava" debug="0" reloadable="true"/>
Hopefully there is some really obvious thing I have overlooked. Please let me know if you can see it.
Remember I can see servlets from the webapps\ROOT\WEB-INF\classes and all HTML and JSPs
in any directory.
Meanwhile I try out some the ideas presented so far. I copied the web.xml file from the examples\WEB-INF and could not see html or jsp but when I put the afore mentioned file I could. I then removed all the path information, created a new app and still encountered the same error.
 
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. I've finally worked it out. Of course it turned out to be a few very simple things that I dont think of at 3am.
Number 1: When I removed all the path information, the reason it wasn't working was because I wasn't opening a new browser. The cache kept displaying the old link... duh to me!
Number 2: Since I found out that the problem with the original was path info, I checked the package name, action link and directory structure and sure enough... the files referred to com.onjava.login and my directory structure was com.onJava.login. (Capitalisation!!).
Anyway thanks for all your suggestions. It really helped not only practically but also to calm me down a little, think a lot clearer and not feel so helpless and frustrated. (And I was really frustrated ).

...Now to get those beans working.
[ March 14, 2002: Message edited by: Caveman Thomas ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the ranks of Tomcat users. The other thing that causes vast frustration is different versions of library jar files hanging around in various places. I think there is now a pretty good discussion of this in the Tomcat docs.
Bill
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CT - Just wanted to point out one thing - web.xml lives under.../appname/WEB-INF, not under ..../appname.
This will be important as you actually start to add configuration information to web.xml.
Regards, Guy
 
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guy
reply
    Bookmark Topic Watch Topic
  • New Topic