Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Servlet not available?  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Author and ninkuma
Marshal
Posts: 66801
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this is not Tomcat-specific, I've moved it to the Servlets forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66801
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps this entry in the JSP FAQ may help?
 
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dean Jones
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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...
 
Sheriff
Posts: 23700
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your web.xml file look like now?
 
Dean Jones
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
What does your web.xml file look like now?



 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you can't see anything that looks off?
 
Dean Jones
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

class MyDean extends HttpServlet {




Should be:

public class MyDean extends HttpServlet {

 
Dean Jones
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like Tomcat can't find the HttpServlet class??

 
Dean Jones
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!