wood burning stoves 2.0
The moose likes Tomcat and the fly likes Difficulties with setting up Apache tomcat: 'Need a little help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Difficulties with setting up Apache tomcat: Watch "Difficulties with setting up Apache tomcat: New topic

Difficulties with setting up Apache tomcat: 'Need a little help.

Femi Alla
Ranch Hand

Joined: Jul 05, 2002
Posts: 79
Greetings everyone,

I would appreciate a little help from all the gurus out there.....

Tomcat refuses to bring up my servlet. I know I've done something wrong somewhere but can't figure out where.

Now let me confess all my wrong deeds:

I'm trying to run servlets (and JSPs) by installing tomcat on j2sdk1.4.0 (and not using J2EE sdk).
I have apache Tomcat 4.1.18 installed.
I set the JAVA_HOME environment variable to the directory where the J2 SDK is installed on c: (c:\j2sdk1.4.0)
I also have APACHE_HOME set to the location of the tomcat installation. But then, while troubleshooting, I also added CATALINA_HOME and made it point to the same location. (My thinking is this wasn't nessesary, but it wouldn't hurt. Was I right?)
I have included all the environment variables below in case it would help....

In the webapps directory which resides in the tomcat installation directory, I have my directory named gsmsecurity, which contains a WEB-INF subdirectory. This WEB_INF subdirectory now contains to other subdirectories: lib and classes. My servlet resides inside the classes folder. Now the examples folder that comes with tomcat is on the same level with my gsmsecurity folder.

After starting tomcat, I point my browser to to bring up the HelloWorld example servlet. But when I do: I get a tomcat error report page: HTTP status 404.
When I try different urls e.g, the result is the same. Even when I put HelloWorldExample inside my classes folder and tried to bring it up, I didn't succed. My conclusion was that this was probably because there was no web.xml file in the WEB-INF folder. I put a minimal amount of things in the xml file and put it up, but the problem persists.

I would appreciate it greatly if someone could tell me what I'm doing wrong here.

Here's a listing of my Servlet. It's s simple one to let me know everything OK,before serious work begins

A listing of my web.xml file:

his is the song tomcat sings anytime it starts up:

My environment variables:

Another question I have is, why does http:\\localhost:8080\blah,blah not work for me?

Maybe it would also help if I mention that I am running Windows 2000 professional without IIS installed.

Thanks for reading up to this point. You could as well kindly pass a comment or two.......

Richard Bradford
Ranch Hand

Joined: Apr 20, 2004
Posts: 48
Try adding a <servlet-mapping> entry in your web.xml file.
Also its a good idea, as well as good practice, to put your serlvet class in a package.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13024
You appear to be using URLs with "/servlet/" in them. This gets you involved with the "invoker" servlet.
Read this FAQ here at the ranch and find out why this is a bad idea.

As Richard said - it is essential to put all classes involved in servlets in a package.
Nidhi Singhal
Ranch Hand

Joined: Sep 19, 2004
Posts: 89

u can try this out...c if this works..

add the following in ur web.xml after <\servlet>

- <servlet-mapping>

and then use the following url to access the servlet
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Moving this thread to the more appropriate Apache/Tomcat forum.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Femi Alla
Ranch Hand

Joined: Jul 05, 2002
Posts: 79
Thanks so much for those answers.

Richard, I've put the class in a package and included the <servlet-mapping>, like you and Nidhi said I should.

And William, I read
The Long and Sordid Tale of the Invoker Servlet
you linked me to and I got the message.
I think I've got it now, only that the page that comes up is blank.
First, I did as the FAQ page said at the begining of the page:
In the file conf/web.xml find a section of text that looks like this:

<!-- The mapping for the invoker servlet -->
You need to uncomment the servlet-mapping and then restart Tomcat. Your application should work now....

I uncommented these lines.
I did this just to see the application work, at least. But knew something was wrong when instead of displaying a webpage, I got a text file downloaded. Then saw it was in the part where the servlet sends the header [code] theResponse.setContentType("text.html"); [/code] . I fixed that to read [code] theResponse.setContentType("text/html"); [/code]. Then I put the servlet in a package named mypackage ( I always prefer to keep things simple at first. The package structure could get deeper later), and I added the <servlet-mapping> tag. But all I get now is a blank page. What am I doing wrong?

In a bid to solve this, I included my classes directory in the classpath. Still didn't work. I then chaged the way output is sent to the browser in the servlet, like this
ServletOutputStream out = theResponse.getOutputStream();
I think it's something to do with my web.xml file.

Listing of my web.xml file:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

<!-- Application that implements Wireless security for GSM networks in this case, Nigeria -->

<display-name>Wireless Security application</display-name>
This application uses a client - server model to implement a Wireless security mechanism for
GSM networks.

I'm supposed to declare parameters here, but chose not to, yet

This parameter represents nothing sensible......

This servlet does this and this.....


<!-- How long to wait before the session times out-->
<!-- 30 minutes -->


Any useful suggestion would be greatly appreaciated.

Chandra Sekhar
Ranch Hand

Joined: Sep 26, 2003
Posts: 90

Your url to invoke the servlet must be like

Check u have the right folder structure like

ur web.xml must be some thing like



and ur server.xml..verfiy u have added ur application
<Context path="/myapp" docBase="myapp" debug="7" reloadable="true">

These are the things u need to run a servlet from ur context(ie an application like myapp)

and abt Invoker servlet..since now u have mapped the servlet,its no longer required.If the mapping is not done (prior to tomcat 4) ur URL to invoke servlet will be like http://localhost:8080/myapp/servlet/HelloServlet

i'm just putting all the points which i learned recently

Chandrasekhar S
[ September 29, 2004: Message edited by: Chandra Sekhar ]

"Luck is when opportunity meets preparation"
I agree. Here's the link: http://aspose.com/file-tools
subject: Difficulties with setting up Apache tomcat: 'Need a little help.
It's not a secret anymore!