For Programmers: Free Programming Magazines  


Home > Archive > Java Help > May 2006 > Running a servlet with Tomcat









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Running a servlet with Tomcat
Matheas Manssen

2006-05-21, 7:09 pm

Hi,

When I use the following URL in Internet Explorer:

http://localhost/servlet/HelloWorldExample

I get an error message:
-----8<------------
HTTP Status 404 - /servlet/HelloWorldExample
--------------------------------------------------------------------------------
type Status report
message /servlet/HelloWorldExample
description The requested resource (/servlet/HelloWorldExample) is not
available.

--------------------------------------------------------------------------------
Apache Tomcat/5.5.17
-----8<------------

I have the HelloWorldExample.class file in
C:\Tomcat5.5\webapps\ROOT\WEB-INF\classes.
Can anyone help me please?

Best regards,

Matheas Manssen


Rhino

2006-05-21, 7:09 pm


"Matheas Manssen" <geheim> wrote in message
news:44708829$0$2023$ba620dc5@text.nova.planet.nl...
> Hi,
>
> When I use the following URL in Internet Explorer:
>
> http://localhost/servlet/HelloWorldExample
>
> I get an error message:
> -----8<------------
> HTTP Status 404 - /servlet/HelloWorldExample
> --------------------------------------------------------------------------------
> type Status report
> message /servlet/HelloWorldExample
> description The requested resource (/servlet/HelloWorldExample) is not
> available.
>
> --------------------------------------------------------------------------------
> apache Tomcat/5.5.17
> -----8<------------
>
> I have the HelloWorldExample.class file in
> C:\Tomcat5.5\webapps\ROOT\WEB-INF\classes.
> Can anyone help me please?
>


It's not enough to simply put your class file in the appropriate Tomcat
directory. You also need a correct web.xml file stored in the proper place
so that Tomcat can find and start your servlet. Have you done that?

--
Rhino


Juha Laiho

2006-05-21, 7:09 pm

"Rhino" <no.offline.contact.please@nospam.com> said:
>"Matheas Manssen" <geheim> wrote in message
>news:44708829$0$2023$ba620dc5@text.nova.planet.nl...
....[color=darkred]
>
>It's not enough to simply put your class file in the appropriate Tomcat
>directory. You also need a correct web.xml file stored in the proper place
>so that Tomcat can find and start your servlet. Have you done that?


That answer is correct - but there is a reason why some (especially a bit
older) books might fail to mention it.

Older servlet containers (like Tomcat 3.3) had something called "invoker
servlet", which enabled HTTP access to all servlets. However, this was
found to be bad security practise, and this servlet is disabled by
default on current Tomcat releases (and likewise on other webapp containers
that I know of).

Currently, the recommended practise (even though it is a bit of extra work
when you're just learning, and only doing small test things) is, as Rhino
wrote, to write a minimal web.xml file for your application and declare
and map your servlets there.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
Matheas Manssen

2006-05-21, 7:09 pm

Hi Rhino,

Thank you for your reply. I looked an example web.xml, and understand now
better how it works.

Cheers,
Matheas
>
> It's not enough to simply put your class file in the appropriate Tomcat
> directory. You also need a correct web.xml file stored in the proper place
> so that Tomcat can find and start your servlet. Have you done that?
>
> --
> Rhino
>



Rhino

2006-05-21, 7:09 pm


"Matheas Manssen" <geheim> wrote in message
news:4470b1c4$0$2022$ba620dc5@text.nova.planet.nl...
> Hi Rhino,
>
> Thank you for your reply.


You're welcome!

> I looked an example web.xml, and understand now better how it works.
>

Since you didn't mention having created a web.xml, I thought I should
mention it; forgetting to create the web.xml file is a common mistake for
someone new to servlets :-)

--
Rhino


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com