File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet not available? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet not available?" Watch "Servlet not available?" New topic
Author

Servlet not available?

Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
So, I have created a new webapp in $CATALINA_HOME/webapps/dean

In that directory I have:
dean.htm
WEB-INF
WEB-INF/web.xml
WEB-INF/classes
WEB-INF/classes/MyDean.class

I can view dean.htm correctly, but I can't seem to get my "MyDean.class" to execute. Everytime I try to go to my servlet at http://snaghosting.com:8080/dean/MyDean I get the error:



Here is what my web.xml



Any ideas?? This is driving me nuts.
[ December 27, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61209
    
  66

As this is not Tomcat-specific, I've moved it to the Servlets forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61209
    
  66

Perhaps this entry in the JSP FAQ may help?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You can usually get away without packaging servlets.
It's never a good idea but I don't think that's the problem here.

Can you post two more things?
1.) The full path to your app.
You've posted from WEB-INF down but where is your app residing on your machine?

2.) The URL you're using when trying to hit this servlet.


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

Joined: Dec 13, 2006
Posts: 23
Ben,

I'm confused... I thought I put all of that stuff in my post.

The application resides in $CATALINA_HOME/webapps/dean

$CATALINA_HOME is /usr/local/tomcat

The URL I'm using to reach the servlet is:

http://snaghosting.com:8080/dean/MyDean
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
Place your servlet in a package, use that package name in the servlet declaration in web.xml and place the compile class under WEB-INF\classes accordingly.

All Java classes used in servlets should be in packages - it will save you lots of grief to just do it that way.

Bill
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Also, if I do try to package it, I get the same error... I've tried to package it under org.cleancode.MyDean and adjust the web.xml file accordingly, but it still says it's not available.
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Originally posted by William Brogden:
Place your servlet in a package, use that package name in the servlet declaration in web.xml and place the compile class under WEB-INF\classes accordingly.

All Java classes used in servlets should be in packages - it will save you lots of grief to just do it that way.

Bill


So at the top of my MyDean.java file I should have something like:

package org.cleancode;

Right? Then when I compile, should I specify the -d option to javac to point to the WEB-INF/classes directory? Or just move the MyDean.class file to the WEB-INF/classes directory??

The former doesn't work, haven't tried the latter yet...
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Just tried the latter, that gives me the same result. Not Available.

So, it all currently looks like this:

$CATALINA_HOME = /usr/local/tomcat
Under that I have: webapps/dean
Under that I have:

dean.htm
WEB-INF/
WEB-INF/web.xml
WEB-INF/classes
WEB-INF/classes/MyDean.class
WEB-INF/classes/org
WEB-INF/classes/org/cleancode
WEB-INF/classes/org/cleancode/MyDean.class

My web.xml file looks like this:



Any more suggestions?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410



Is this up on a hosted server?
If so, the first thing I would do is put a simple html page in the 'dean' directory and see I can hit it.


Also, for the record, I agree with William and others here.
There is never a good reason not to package a Java class.
In a serlvet app, there are particular cases where you can get away with it and cases where you can't.
It's a complete waste of your brain's CPU cycles to try to learn when you can and can't.
Just package everything.
That being said, I don't think packaging is the problem in this case.
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Originally posted by Ben Souther:


Is this up on a hosted server?
If so, the first thing I would do is put a simple html page in the 'dean' directory and see I can hit it.


Also, for the record, I agree with William and others here.
There is never a good reason not to package a Java class.
In a serlvet app, there are particular cases where you can get away with it and cases where you can't.
It's a complete waste of your brain's CPU cycles to try to learn when you can and can't.
Just package everything.
That being said, I don't think packaging is the problem in this case.


Yes, it's on a hosted server. You should be able to get to it with no problem. I have the dean.htm file in that webapp that you can see by going to:

http://snaghosting.com:8080/dean/dean.htm

It shows fine. However, The servlet still isn't available. Here is my servlet code:



I compiled it in the directory of /usr/local/tomcat/webapps/WEB-INF/classes with:

javac -classpath /usr/local/tomcat/common/lib/servlet-api.jar -d . MyDean.java

Am I doing something wrong?
[ December 28, 2006: Message edited by: Dean Jones ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Your directory structure (under WEB-INF) has to match your package structure.
For instance if my servlet were in package us.souther, then its class file would need to be under WEB-INF/classes/us/souther.

Your references to that class file in your deployment descriptor (web.xml) will also need to be fully qualified.
<servlet-class>us.souther.MyServlet</servlet-class>

Also, you've only implemented the doPost method.
You'll need to implement the doGet method if you want to access it directly from a hyperlink or by typing the address into your browser's window.
[ December 28, 2006: Message edited by: Ben Souther ]
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Originally posted by Ben Souther:
Your directory structure (under WEB-INF) has to match your package structure.
For instance if my servlet were in package us.souther, then its class file would need to be under WEB-INF/classes/us/souther.

Your references to that class file in your deployment descriptor (web.xml) will also need to be fully qualified.
<servlet-class>us.souther.MyServlet</servlet-class>

Also, you've only implemented the doPost method.
You'll need to implement the doGet method if you want to access it directly from a hyperlink or by typing the address into your browser's window.

[ December 28, 2006: Message edited by: Ben Souther ]


I believe the directory structure is correct:

WEB-INF/
WEB-INF/web.xml
WEB-INF/classes
WEB-INF/classes/org
WEB-INF/classes/org/cleancode
WEB-INF/classes/org/cleancode/MyDean.class

Yes?

Right now I'm trying to only post stuff to my servlet from dean.htm. However, it says servlet is not available no matter if I implement a doGet or not...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I compiled it in the directory of /usr/local/tomcat/webapps/WEB-INF/classes...
I'm not really familiar with Tomcat, but shouldn't there be a "/dean/" somewhere in there? Or are you deploying the compiled classes into a path that does have "/dean/" in it?
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Originally posted by Paul Clapham:
I'm not really familiar with Tomcat, but shouldn't there be a "/dean/" somewhere in there? Or are you deploying the compiled classes into a path that does have "/dean/" in it?


Look at my original post. dean is in webapps. So it looks like this:

Everything is in /usr/local/tomcat/webapps

dean/
dean/dean.htm
dean/WEB-INF
dean/WEB-INF/web.xml
dean/WEB-INF/classes
dean/WEB-INF/classes/org
dean/WEB-INF/classes/org/cleancode
dean/WEB-INF/classes/org/cleancode/MyDean.class

So, yes, there is a "/dean/" in there. It's under the webapps directory. I was just considering that this was given since my first post. Sorry.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What does your web.xml file look like now?
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Originally posted by Ben Souther:
What does your web.xml file look like now?


Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you want to test pre-compiled and configured app, I have some war files on my site.
http://simple.souther.us
Look for SimpleServlet.

Just drop the war file in your webapps directory and alter the link on my site to point to your host instead of localhost:8080.

If that works, you might want to compare what's in there with what you're writing to see what might be different.
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
So you can't see anything that looks off?
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Ok, It seems I get a new error when trying to access the servlet for the first time. However, when I refresh or try to access the servlet again, it goes back to the "Not available" error...

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

class MyDean extends HttpServlet {



Should be:
public class MyDean extends HttpServlet {
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
It seems like Tomcat can't find the HttpServlet class??

Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Ben,

Yes! You're right. How freakin blind was I?!

Going from C++ to Java. I'm bound for more screw ups like that!

Thanks Ben. Works now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet not available?