error 404 with servlet not found...newbie question

M

marco

Good day,

my issue is basically I have a very simple setup of a webappliction.
A couple of jsp pages and a couple of servlets.

If I copy my classes into...

C:\jakarta-tomcat-5.0.19\webapps\ROOT\WEB-INF\classes

everything works...if I copy the same classes into

C:\jakarta-tomcat-5.0.19\webapps\ROOT\test\WEB-INF\classes

I get a 404 error. Now I know that my classes are working...and also
that my jsp pages are working.

I have tried several things...here is what I placed in my server.xml:


<Context path="/DiscoverRealtor/"
docBase="DiscoverRealtor"
debug="1"
reloadable="true">
</Context>

I have changed several times the CLASSPATH, and I have also added the
entire path into it...with no success...

if my classpath has the following:

C:\jakarta-tomcat-5.0.19\webapps\ROOT\WEB-INF\classes

everything works...if I put

C:\jakarta-tomcat-5.0.19\webapps\ROOT\test\WEB-INF\classes

it does not work...yet I know that the files are there and that they
work...

Any help would be greatly appreciated!!


Marco
 
C

Chris Smith

If I copy my classes into...

C:\jakarta-tomcat-5.0.19\webapps\ROOT\WEB-INF\classes

everything works...if I copy the same classes into

C:\jakarta-tomcat-5.0.19\webapps\ROOT\test\WEB-INF\classes

I get a 404 error.

Yes, this is expected. The proper place to put your classes is in a
directory called WEB-INF/classes, relative to the context root. A
directory called test/WEB-INF/classes will not work, except to make the
class files available directly from the web server.

If you want to map your web application to a different URL, then you
need to create a NEW context and map it. You can't just put everything
inside the 'ROOT' context. Try putting your files in:

C:\jakarta-tomcat-5.0.19\webapps\test\WEB-INF\classes

If you don't have auto-deplying enabled from the webapps directory, then
you'll also need a Context element in Tomcat's server.xml; but unless
you've changed the configuration in that way, this should work out of
the box.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
W

William Brogden

Good day,

my issue is basically I have a very simple setup of a webappliction.
A couple of jsp pages and a couple of servlets.

If I copy my classes into...

C:\jakarta-tomcat-5.0.19\webapps\ROOT\WEB-INF\classes

everything works...if I copy the same classes into

C:\jakarta-tomcat-5.0.19\webapps\ROOT\test\WEB-INF\classes

I get a 404 error. Now I know that my classes are working...and also
that my jsp pages are working.

I have tried several things...here is what I placed in my server.xml:


<Context path="/DiscoverRealtor/"
docBase="DiscoverRealtor"
debug="1"
reloadable="true">
</Context>

I have changed several times the CLASSPATH, and I have also added the
entire path into it...with no success...

if my classpath has the following:

C:\jakarta-tomcat-5.0.19\webapps\ROOT\WEB-INF\classes

everything works...if I put

C:\jakarta-tomcat-5.0.19\webapps\ROOT\test\WEB-INF\classes

it does not work...yet I know that the files are there and that they
work...

Any help would be greatly appreciated!!


Marco

1. Tomcat totally ignores your environment classpath - see the classloader
how-to pages installed with tomcat for how it looks up classes.
2. ROOT already has a classes - in the right place for the servlet API.
If you want to create a new "test" web application directory, place it
under /webapps
3. Download the servlet API from
http://java.sun.com/products/servlet/
to get the exact information on servlets in web applications, web.xml, etc.


Bill
 
B

Bryce

Good day,

my issue is basically I have a very simple setup of a webappliction.
A couple of jsp pages and a couple of servlets.

If I copy my classes into...

C:\jakarta-tomcat-5.0.19\webapps\ROOT\WEB-INF\classes

everything works...if I copy the same classes into

C:\jakarta-tomcat-5.0.19\webapps\ROOT\test\WEB-INF\classes

I get a 404 error. Now I know that my classes are working...and also
that my jsp pages are working.

I have tried several things...here is what I placed in my server.xml:


<Context path="/DiscoverRealtor/"
docBase="DiscoverRealtor"
debug="1"
reloadable="true">
</Context>

I have changed several times the CLASSPATH, and I have also added the
entire path into it...with no success...

You shouldn't have to change the classpath. Tomcat will take care of
that for you.

What you aren't tell us is:

1. What does your web.xml look like?
2. What URL are you trying to access your servlets with.
 
M

marco

Bryce said:
You shouldn't have to change the classpath. Tomcat will take care of
that for you.

What you aren't tell us is:

1. What does your web.xml look like?
2. What URL are you trying to access your servlets with.

Thank you very much for all your help!!! I works perfectly!!!

Here is my setup that I have now...

Web.xml I left empty for now...I will add to it as I go along...
In the the Server.xml file I added

<Context path="webapps/test/"
docBase="test"
debug="1"
reloadable="true">
</Context>

Directory structure:

C:\jakarta-tomcat-5.0.19\webapps\test
-css
-images
(all jsp files)
...
-WEB-INF
-classes
(all my servlets)
-lib
(all my *.jar files)

The main issue that I had was to know what path to use when I called a
servlet from a jsp page / form...here is an example:

<form action="http://localhost/test/servlet/main.userlogin"
method="post">

and the next issue was to know how to forward(path) the jsp after the
"userlogin" and that was...
(java file)
String address = "/logged.jsp";
RequestDispatcher dispatcher =
request.getRequestDispatcher(address);
dispatcher.forward(request, response);

So, thx again for all your help...

Marco

I got a fever, and the only prescription is more cowbell!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top