File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet problem" Watch "Servlet problem" New topic

Servlet problem


Joined: Oct 11, 2002
Posts: 12
HI, everyone,
I am a beginner in servlets and met a lot of problems. I will appreciate if u can do me a favour.

My problem is: In Tomcat4, I create a new folder named "AA" inside the webapps directory and in AA I also create a subdirectory named WEB-INF, then I copied hello.class and file to that WEB-INF. After that I created a web.xml file like
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

in the WEB-INF directory.

When I typed http://localhost:8080/AA/servlet/Hello in my browser, it has error. But when I typed http://locahost:8080/examples/servlet/HelloWorldExample , it works. Why?

Many thanks,

Nikki Aniban

Joined: Oct 10, 2002
Posts: 14
Hi Qing!
Create a "classes" directory inside your WEB-INF and put all your class files there. This is the standard directory structure for web applications.
Also note that accessing your servlet is case sensitive so if your file name is hello.class, you should use http://localhost:8080/AA/servlet/hello to call it.
This should work. Goodluck!

Joined: Oct 11, 2002
Posts: 12
Thanks, but it still can not work. It is said "description The requested resource (/AA/servlet/Hello) is not available". I am a little crazy by this.
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
HI, you need to add a context entry in the server.xml file.For exact syntax,open server.xml & look the the 'examples' context.You may try moving the AA folder to \tomcat\ROOT\ also.

Joined: Oct 11, 2002
Posts: 12
Actually, I didn't make any change to the server.xml or else. I found the java class in my AA folder works when I moved the folder "compressionFilters", "error", "filters" and "listeners" from "examples"'s subdirectory classes to the "AA"'s subdirectory classes. And I also moved the "jsp" folder from "examples"'s WEB-INF folder to AA's WEB-INF folder.
Who can tell me why?
I found from one file named that it is writen to " compress the ServletResponse if it is bigger than a threshold".
Life is not so easy. aha?
Many thanks for any answer and suggestions.
BTW, I am using TOMCAT4.1.12, JDK1.4, Win2k.
Trish Wu
Ranch Hand

Joined: Oct 09, 2002
Posts: 34
In your webapp AA/WEB-INF/web.xml
please add a servlet-mapping entry
with these values:
servlet-name: invoker
url-pattern: /servlet/*
So what it does is to tell the container to serve the servlet class by its fully qualified class name.
The container will look for the a servlet with classname:
And also make sure that the classes dir in WEB-INF contains the above class file.
The stack trace of the error your are getting saying that the resource cant be found or something is actually appearing in the log directory :
<YOUR TOMCAT>\logs\localhost_log.2002-10-13.txt
It is a good idea to look at the log file to get some ideas when u are stuck
good luck!
I agree. Here's the link:
subject: Servlet problem
It's not a secret anymore!