Tomcat 5.0.25 my own servlet example doesn't run.

M

mojgan

Hi,
I recently installed Tomcat 5.0.25 on Windows XP, and all seems fine.
All the examples that come with it run, no problem.

So as a first step, I tried to edit the HelloWorldServlet.java file to
display something else, like "Howdy Yall!". I edited the file, and
recompiled without error. When I click on the link to execute this
HelloWorldServlet example, it still shows "Hello World". I deleted all
my cookies and cached internet files, thru the browser, but I still
see the same thing. I even removed the HelloWorldServlet.class file,
but it still shows "Hello World".

What's going on? Is it looking in a jar somewhere? I don't get it.

The path is like this:
c:\tomcat\webapps\servlets-examples\WEB-INF\classes\HelloWorldServlet.class

Basically it's what comes with the standard installation, I just
wanted to see if I could modify what already works before I made my
own servlet.

I also tried to write my own servlet (very similar to the
HelloWorldServlet.java) and modified the web.xml file, similar to the
settings for the existing examples. But when I point my browser to the
new example, I see a page with this:

HTTP Status 404 - /servlets-examples/servlet/HelloExample
----------------------------------------------------------
type Status report
message /servlets-examples/servlet/HelloExample
description The requested resource
(/servlets-examples/servlet/HelloExample) is not available.
----------------------------------------------------------
Apache Tomcat/5.0.25

I would appreciate any help I could get.
Regards,
..mojgan.
 
K

kjc

Did you restart the server. It's not going to reload a class definition
from an a directory hieararchy that isn't bundled into a WAR.
 
W

William Brogden

Hi,
I recently installed Tomcat 5.0.25 on Windows XP, and all seems fine.
All the examples that come with it run, no problem.

So as a first step, I tried to edit the HelloWorldServlet.java file to
display something else, like "Howdy Yall!". I edited the file, and
recompiled without error. When I click on the link to execute this
HelloWorldServlet example, it still shows "Hello World". I deleted all
my cookies and cached internet files, thru the browser, but I still
see the same thing. I even removed the HelloWorldServlet.class file,
but it still shows "Hello World".

What's going on? Is it looking in a jar somewhere? I don't get it.

The path is like this:
c:\tomcat\webapps\servlets-examples\WEB-INF\classes\HelloWorldServlet.class

Basically it's what comes with the standard installation, I just
wanted to see if I could modify what already works before I made my
own servlet.

I also tried to write my own servlet (very similar to the
HelloWorldServlet.java) and modified the web.xml file, similar to the
settings for the existing examples. But when I point my browser to the
new example, I see a page with this:

HTTP Status 404 - /servlets-examples/servlet/HelloExample
----------------------------------------------------------
type Status report
message /servlets-examples/servlet/HelloExample
description The requested resource
(/servlets-examples/servlet/HelloExample) is not available.
----------------------------------------------------------
Apache Tomcat/5.0.25

I would appreciate any help I could get.
Regards,
.mojgan.

1. the URL /servlet/HelloExample depends on the "invoker" servlet
short-cut.
Look at this http://faq.javaranch.com/view?InvokerServlet
JavaRanch FAQ for why this is a bad idea
2. You should always put all classes involved in servlets into packages
and set up web.xml and the class location accordingly to avoid all sorts
of hard to figure out error messages.

Bill
 
M

mojgan

I restarted the Tomcat, but it still shows "Hello World". I didn't see
mention of WARs in the tutorials.

In general, if I'm writing a servlet what's the best approach to test
it, modify it, and test again, etc?
1. Write the .java code
2. Compile, put the .class file in the classes\ directory
3. Make sure the web.xml file is defining the correct references to
that servlet
4. then what???

Also, if WARs are the way to go, is there a quick reference that you
can point me to?

Thanks,
..mojgan.
 
M

mojgan

Correction, I restarted Tomcat and my change and my new servlet
worked/loaded fine.

Will I have to restart Tomcat *everytime* I make a change to my
servlet and recompile??? During the development phase, this could be
quite often.

Thanks,
..mojgan.
 
W

William Brogden

Correction, I restarted Tomcat and my change and my new servlet
worked/loaded fine.

Will I have to restart Tomcat *everytime* I make a change to my
servlet and recompile??? During the development phase, this could be
quite often.

Thanks,
.mojgan.

Read the documentation on the Management application. It very
elegantly lets you force a reload of a given servlet without
disturbing other applications.

Bill
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top