• 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

Servlet launch from browser - error "Requested resource is not available".

 
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, everyone! I truly hope you can help.

I am well aware there have been many, many related questions asked already about this, as well as even more answers. Unfortunately, having tried all this advice I still cannot resolve this problem.

I am trying to launch a simple Java servlet in the browser, following instructions from the textbook:

Java Programming: Comprehensive Concepts and Techniques, Shelly Cashman Series, ISBN: 9781418859855.

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).

3) In the browser, type URL: http://localhost:8080/servlet/HTMLBank and enter it. After doing this, the following error results:

HTTP Status 404 - /servlet/HTMLBank
type Status report
message /servlet/HTMLBank
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!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The book likely predates the change in Java where packageless servlets will not work.

You are unlikely to get this to work without placing the servlets in a package. Additionally check out the ServletsFAQ for additional tips.
 
Yevgeni Duvenage
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Bear.

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.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yevgeni Duvenage
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Dave.

That does make sense, thanks, I agree. I'll likely have to use a more "modern" and thus applicable approach to launch the servlets.
 
Yevgeni Duvenage
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Dave Tolls
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SEVERE: Parse error in application web.xml
org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.


That implies your web.xml is incorrect.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And this tells you where to look:

SEVERE: Parse Fatal Error at line 42 column 2: The content of elements must consist of well-formed character data or markup.
 
Rancher
Posts: 5008
38
 
Yevgeni Duvenage
Greenhorn
Posts: 28
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, thanks a lot for all the help!!!

With your suggestions, I found the problem:

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.

Thanks a lot to everybody for this!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting back with what you found. That's sure to help others in the future.
 
BWA HA HA HA HA HA HA! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic