wood burning stoves 2.0*
The moose likes Servlets and the fly likes Tomcat - The requested resource is not available Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Tomcat - The requested resource is not available" Watch "Tomcat - The requested resource is not available" New topic
Author

Tomcat - The requested resource is not available

Gary Conway
Greenhorn

Joined: Feb 07, 2006
Posts: 2
I am trying to complete a simple Hello World servlet example.

I have installed Tomcat 5.5 and the relevant java kits so that I can now view the Tomcat main page from http://localhost:8080/.

I have followed my book (Jess in Action) example and created the directory structure:

Tomcat 5.5\webapps\Hello\WEB-INF\classes

and added a web.xml file to the WEB-INF directory.

I have placed my Hello.java file in the classes folder and successfully compiled it so I assume my classpaths are all correct.

However, when I view the page http://localhost:8080/Hello/servlet/Hello all that is displayed is:

HTTP Status 404 - /Hello/servlet/Hello

type: Status report

message; /Hello/servlet/Hello

description: The requested resource (/Hello/servlet/Hello) is not available.


Can anybody see if I have missed something?

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes.
Tomcat, by default, now ships with the invoker servlet disabled (commented out in the web.xml file). You now need to create a 'servlet' and a 'servlet-mapping' entry in your web.xml.

Once you do, you can get rid of the "servlet/" part of your url.

Check out the following URL for more information regarding the invoker servlet:
http://faq.javaranch.com/view?InvokerServlet


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gary Conway
Greenhorn

Joined: Feb 07, 2006
Posts: 2
Thanks Ben, it's now working

Much appreciated
Jay Brimestone
Greenhorn

Joined: Feb 06, 2010
Posts: 1
I am having the same problem. I successfully compiled my Ch1Servlet.java file so it is now a .class file in my tomcat/webapps/ch1/WEB_INF/classes directory. I also included this in my web.xml file which is located in my /WEB-INF directory:

<?xml version="1.0" encoding="ISO-8851-1" ?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>

</web-app>

When I try to access the servlet at http://localhost:8080/ch1/Serv1, I am still receiving the "error 404", "The requested resource () is not available.", "type status report". Can anyone assist?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Go back and read that Invoker servlet article again.



ALL classes used in servlets should be in a package and the class file located according to the package.

The reason being that the JVM will look for your (no package) class in the "current" directory - you have no control over what Tomcat considers the current directory.
Christian Cabizza
Greenhorn

Joined: Feb 06, 2010
Posts: 2
Jon Bexiga wrote:I am having the same problem. I successfully compiled my Ch1Servlet.java file so it is now a .class file in my tomcat/webapps/ch1/WEB_INF/classes directory. I also included this in my web.xml file which is located in my /WEB-INF directory:

<?xml version="1.0" encoding="ISO-8851-1" ?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>

</web-app>

When I try to access the servlet at http://localhost:8080/ch1/Serv1, I am still receiving the "error 404", "The requested resource () is not available.", "type status report". Can anyone assist?


Oh... I have the same problem... and I'm too newbie to understand the article... help me pleaseeee!


Christian Cabizza
Junior Java Developer at Nexus S.r.l.
Christian Cabizza
Greenhorn

Joined: Feb 06, 2010
Posts: 2
Jon Bexiga wrote:I am having the same problem. I successfully compiled my Ch1Servlet.java file so it is now a .class file in my tomcat/webapps/ch1/WEB_INF/classes directory. I also included this in my web.xml file which is located in my /WEB-INF directory:

<?xml version="1.0" encoding="ISO-8851-1" ?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>

</web-app>

When I try to access the servlet at http://localhost:8080/ch1/Serv1, I am still receiving the "error 404", "The requested resource () is not available.", "type status report". Can anyone assist?


Well... I'm so sorry...
My problem was in charachter set: try to substitute:

<?xml version="1.0" encoding="ISO-8851-1" ?>

with

<?xml version="1.0" encoding="UTF-8" ?>
Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

Hi,
How does the encoding afftect the web.xml?
That is one part of web.xml that I have never paid attention to . Could someone please clarify.


Cheers,
Roy.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
http://cs.nyu.edu/~rpm319
Robyn Morin
Greenhorn

Joined: Mar 21, 2010
Posts: 3
Thanks for posting this... the change to UTF-8 saved what is left of my already fleeting sanity.
I have been researching this problem to no avail for weeks.

Robyn
Danny Glover
Greenhorn

Joined: Apr 16, 2010
Posts: 3
Hi everybody,

Needless to say I've the same problem with my Tomcat application that you all were mentioning. I'm running my tomcat in a virtual CentOS machine on my laptop, and I've even modified the encoding to UTF-8, but the problem persists...My app is called snoopy and the web.xml looks like this:


The app is present in the /webapps directory, but I'm getting nowhere through the inumerable restarts and reconfigurations:

[root@localhost webapps]# ls
balancer jsp-examples ROOT servlets-examples snoopy snoopy.war tomcat-docs webdav

A problem with the recompiling of the .war file perhaps? Dunno, suggestions are welcome (I've already looked at the page mentioned by Ben, to no avail.)
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3060
    
  38

"Mindless Abomination", please check your private messages regarding an important administrative matter.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Please read: UseCodeTags

And put your servlet in a package other than the default. This is a recording.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Danny Glover
Greenhorn

Joined: Apr 16, 2010
Posts: 3
Bear Bibeault wrote:Please read: UseCodeTags

And put your servlet in a package other than the default. This is a recording.


sorry Bear, I didn't quite understand what you meant. Could you be a little more specific?

Thanks a lot,

Dan

PS Promise I'll use quotes next time
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3060
    
  38

"Mindless Abomination", please understand that it is mandatory to follow the instructions of the private message which I sent to you.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3060
    
  38

Mindless Abomination wrote:sorry Bear, I didn't quite understand what you meant. Could you be a little more specific?

It's about your servlet class. You should package it using a proper package definition.
Then use the fully-qualified class name for the <servlet-class> element.
Danny Glover
Greenhorn

Joined: Apr 16, 2010
Posts: 3
Devaka Cooray wrote:
Mindless Abomination wrote:sorry Bear, I didn't quite understand what you meant. Could you be a little more specific?

It's about your servlet class. You should package it using a proper package definition.
Then use the fully-qualified class name for the <servlet-class> element.

Roger that , thanks for the tip. I'll change my name if you insist
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3060
    
  38

Mindless Abomination wrote:I'll change my name if you insist

Please check your private messages for a warning.
Benson Sebastian
Greenhorn

Joined: Sep 30, 2010
Posts: 1


whenever this message comes,it clearly means there is smthng wrong in your web.xml file........check if every start tag has an end tag and vice versa....

also make sure you dont miss the / in servlet mapping tag
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Welcome to javaRanch .


SCJP6.0,My blog Ranchers from Delhi
Han Jie
Greenhorn

Joined: Sep 24, 2010
Posts: 24
hi Gary

Maybe if you take your all codes here, others can help you solve it more possibility.

What's your opinion?
Simon Wilsona
Greenhorn

Joined: Oct 28, 2010
Posts: 2
Hi

Along with it seems everyone else who has tried the Head First Servlet book, I cannot make this work.

I have read through this thread, and various other on the internet. Changed my web.xml (repeatedly), put my source in a package, all to no avail.

Could some kind person who has fought their way through this provide a full working example of the web.xml & tomcat directories?

Thanks

Simon
J Adcock
Greenhorn

Joined: Nov 27, 2010
Posts: 1
For what it is worth, I just started the Heads First Servlet and JSP book as well. I am running Fedora with tomcat6. I got the example to work by creating a directory called WEB-INF and a classes subdirectory in WEB-INF. I copied the web.xml file into WEB-INF and the Ch1Servlet.class to WEB-INF/classes/. My web.xml was:


Srinivasa Kumar Meda
Greenhorn

Joined: Dec 10, 2010
Posts: 6

You need to give fully qualified name for the Servlet Class.
Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 46

Hi everybody,
I am working with JSP and Java Beans in my project , my .war file is inside C:\Program Files\apache-tomcat-6.0.32\webapps folder, when I try to run it from tomcat manager it gives error
HTTP Status 404-The requested resource (/StoreManagement/) is not available.
Can anybody tell me what I missed?
Thank you in advance!

Divya
SCJP1.6
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 122
I had declared the class as default access type. Declaring it as public solved my problem. Even I was getting the 404 error. I tried everything mentioned above but careful reading of the tomcat logs showed following errors


eventually, I realized my mistake.


SCJP 6 83%
Working on SCWCD/OCPJWCD
Lina Zhukov
Greenhorn

Joined: Oct 15, 2011
Posts: 1
I had the same problem, if anyone else is looking for a solution and comes across this putting the dependency in pom.xml fixed it


<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
naval kumar
Ranch Hand

Joined: Jul 08, 2012
Posts: 37
i am converting my whole application on Tomcat. So When i am doing copy paste the web.xml as it is , it is giving error The requested resource (/resume/) is not available..But if i m Doing One by One calling Servlet Its working Fine So i want to Ask One things that At the time of running tomcat First Search All the Entry Of web.xml is it exist or not?? Means It serch all the entry inside of this??
<servlet>
<servlet-name>closingAuction</servlet-name>
<servlet-class>com.ireps.auction.utilities.CloseForwardAuction</servlet-class>
</servlet>

But if am doing entry one by one in web.xml and copy paste the struts-config.xml All The Entry , Then It is not showing the error.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Devin Crane,
Your post was moved to a new topic.
 
jQuery in Action, 2nd edition
 
subject: Tomcat - The requested resource is not available