I am aware of the advice given here to other people with this/similar problems, that servlets should preferably be written under a package, and not packageless, but I am following the textbook's guidance with this, and of course being a textbook, its method must work. I seek help with doing it in THIS method.
I have a Java servlet, called HTMLBank.java which I successfully compiled with no compilation errors. Now, according to the textbook:
1) Place the .class file into C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes folder. Yes, the textbook uses the default package for this and the ROOT directory of Tomcat.
2) Run the Tomcat service - it is running (shown as a green "play" arrow in right-bottom of the screen).
HTTP Status 404 - /servlet/HTMLBank
type Status report
description The requested resource (/servlet/HTMLBank) is not available.
Now, I might mention that I did succeed in launching a servlet once before, but that was only if I used a package, say com.example and mapped it in the web.xml file, but as stated before, this deviates from the textbook and I need to get it to work using the default package and ROOT directory.
Here is the code of the HTMLBank.java servlet file:
Here is the code of the web.xml file:
The web.xml file was modified per book guide to allow locating anonymous servlets in the default directory.
Here is the context.xml file:
This file was edited to enable servlet reloading, also as per book guide.
The following are paths to all the files/folders involved in this discussion:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes --> I created the "classes" folder, per book guide.
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes\HTMLBank.class --> I placed the .class file into here.
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\web.xml --> This is the location of web.xml file which was edited.
C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\context.xml is the location of the context.xml file which was edited.
So, as I said, I NEED to work the servlet without a package and from ROOT.
Please can somebody help? I greatly appreciate it!
That is very valuable information in your response, thank you.
Yes, I have JDK 1.5.xxx so then the default servlets probably don't work. Still I'm shocked that the textbook, in which the CD with this version of Java and Tomcat came, makes no slightest note anywhere about the consideration you stated. I'll try to get it to work using packages then.
I do question learning Java in such detail using a book that appears to be quite old (the one on Amazon is from 2005).
There will be a lot of things in there that simply aren't applicable anymore.
In addition, since the book seems to cover absolutely everything, from Applets, to AWT, to Swing, to JDBC, and onto Servlets, I wouldn't be surprised that some of the stuff they cover was already out of date when it was published.
posted 1 year ago
That does make sense, thanks, I agree. I'll likely have to use a more "modern" and thus applicable approach to launch the servlets.
posted 1 year ago
Guys, I insert here the content of an error log file generated by Tomcat. I am a novice at Java, so to me it does not explain much, but could you please go through it and see if it is of any use to find the issue? Thanks.
posted 1 year ago
SEVERE: Parse error in application web.xml org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
It was indeed in line 42 of the web.xml file - the comment beginning tag had a typo, was typed as <-- while must have been <!--. Almost 3 weeks of searching in wrong places because I never would have thought to check something like this.