Forum Moderators: phranque

Message Too Old, No Replies

My First Tomcat App

404 error

         

gbergeron

3:06 pm on May 28, 2003 (gmt 0)

10+ Year Member



I have a dead easy html that just calls a java class
<FORM METHOD=GET ACTION="servlet/CurrencyConverter">

I place my html file in <CATALINA_HOME>\webapps\basic-servlet
and my java class in <CATALINA_HOME>\webapps\basic-servlet\WEB-INF\classes

I stop and start Tomcat and invoke the html. Does anyone know why I get a 404 error back with following message?
The requested resource (/basic-servlet/servlet/CurrencyConverter) is not available.

I started putting a copy of my class file CurrencyConverter just about every where and still no luck. Also, I do have my classpath set to include the Tomcat servlet.jar.

SEO practioner

3:21 pm on May 28, 2003 (gmt 0)

10+ Year Member



Hello gbergeron and welcome to webmaster world!

Well, I did get similar error messages with tomcat too.
Make sure that all your paths are ok and that all the right files are in the right sub directories.

What I recommend is start from scratch, making sure that your application is deployed exactly as it is on your local machine, using FTP.

Thats what I did and now our e-commerce application is running fine.

Good luck

gbergeron

3:34 pm on May 28, 2003 (gmt 0)

10+ Year Member



Thanks. I actually built the app on my machine. Given the simplicity of the system, and that I copied and pasted all my pathnames, I'm wondering what could cause it to fail.

in my HTML form I use the relative path
ACTION="servlet/CurrencyConverter"

So CurrencyConverter.class has been placed in <CATALINA_HOME>\webapps\basic-servlet\WEB-INF\classes (among other places). Shouldn't that work?

SEO practioner

4:22 pm on May 28, 2003 (gmt 0)

10+ Year Member



Make sure that all your paths are ok and that all the right files are in the right sub directories.

txbakers

6:42 pm on May 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With Tomcat, I would put everything at the ROOT level first, then work from that.

Directories are a pain, since there are essentially two paths in Tomcat - one for your actual files and classes, and the other to hold the compiled java classes to display.

For the default context, your classes would go:
<catalina-home>/webapps/ROOT/Web-inf/classes

any directories below this would be used for packages and beans.

Your JSP/HTML page would go in the ROOT folder.

Give that a try and see if it works.

gbergeron

8:58 pm on May 28, 2003 (gmt 0)

10+ Year Member



I tried putting the html page in ROOT, restarted Tomcat. When I access the page [localhost:7080...]

and get a 404 error. Tomcat does not seem that complex to me, yet I'm having a heck of time getting a very basic app up and running. Before I get into deployment descriptors, I want to have basic example working first. Has anybody got Tomcat working without using a deployment descriptor?

bcc1234

9:09 pm on May 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's easier to configure another host and webapp than to use the default one. It already has lots of apps there.

Once you add a host, make sure that you either use invoker servlet or declare your servlet in web.xml otherwise tomcat won't know what to do with that url.

added:
About the html files, drop the ROOT part and check the logs. Tomcat is very verbose in describing what's going on once you start it.

txbakers

9:58 pm on May 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't put "ROOT" in the URL. The default installation is localhost:7080/yourpage.html

If you create another folder at the same level of "ROOT" then you need to include it in your URL. You will also have to create a WEB-INF directory under that and a classes folder under that.

For now, get your default working properly, then expand from there.

gbergeron

10:47 pm on May 28, 2003 (gmt 0)

10+ Year Member



I really thank everyone for their replies. Invoking the form from the ROOT folder works fine

My form displays and when the submit button is pressed it has <FORM METHOD=GET ACTION="servlet/CurrencyConverter">

No matter where I put the class CurrencyConverter, I get a 404 message back. I put the class in webapps\ROOT\WEB-INF\classes
and restarted Tomcat - no luck.

1. Does Tomcat automatically look for classes in folders WEB-INF\classes (i.e. in the ACTION call above, how does it know where to look?)

2. If I have my form in ROOT, should I change my ACTION to "http://localhost:8080/ROOT/servlet/CurrencyConverter"? (assuming question 1 holds true and it automatically looks in WEB-INF\classes)

gbergeron

10:55 pm on May 28, 2003 (gmt 0)

10+ Year Member



Actually using an ACTION of "http://localhost:8080/ROOT/servlet/CurrencyConverter" redirected me to a web page (probably the current one open) instead of a 404 error. I checked the log files but did not find any error messages.

If the java program does bomb, is there anyway to see why it died? Invoking the program in standalone does not work because it does not have a main method.

SEO practioner

11:08 pm on May 28, 2003 (gmt 0)

10+ Year Member



Gbergeron

Tomcat is really tricky and even at times sneaky when it comes to class paths and file paths... that is where we got stuck the most. After a lot of trials and errors, we finally got the beast to work, but it was messy at times.

Once tomcat runs, you have the ball rolling. You will know all is ok when Tomcat brings you to a default-test page on the Tomcat / Apache web site that will tell you:

"If you see this page, it means your Tomcat app. server is properly configured". After seeing that, I guarantee you will have a big grin on your face... We did...

:-)

Hope that helps

gbergeron

12:03 am on May 29, 2003 (gmt 0)

10+ Year Member



Actually I got the Welcome Screen awhile ago. I just can't get this #$$@* Tomcat to execute the servlet.

I actually wrote SAMS publishing and they offered my money back - said the authir (Martin Bond) was not being responsive on this issue. I guess I'm not the first person to follow exactly what the book says and still not get it to work. Yet Tomcat does work. I don't know why I can't mine to call a simple servlet.

txbakers

7:02 am on May 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't care for Tomcat at all. I downloaded the developer version of JRun from Macromedia, and it worked first time out of the box (so to speak).

Give it a whirl and see if it helps you get going faster than Tomcat.

bcc1234

9:53 am on May 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you read what I said about the invoker servlet and web.xml?

Ask yourself, how would tomcat know what to execute when you request that URL?

I would not use invoker if I were you, but instead would list it in web.xml.

rharri

11:48 am on May 29, 2003 (gmt 0)

10+ Year Member



bcc1234 is right. You've got to declare the context in web.xml. If you get it right, Tomcat will show the path during startup.

Bob

gbergeron

8:31 am on May 29, 2003 (gmt 0)

10+ Year Member



After 2 days of frustration, my invocation finally worked.
Even though the log files say it is loading from

Tomcat 4.1\webapps\basic-servlet\WEB-INF\classes

it never worked. I also tried ROOT but same result.

When I loaded it into
Tomcat 4.1\webapps\examples\WEB-INF\classes it worked.

I don't think I configured it wrong because the log files do reference the basic-servlet folder. I'd like to get it working under basic-servlet though. Anybody have any suggestions?

Thanks so much for all the replies (I'm learning a lot though)