aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet problem" Watch "Servlet problem" New topic
Author

Servlet problem

CoffeeFan
Greenhorn

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 hello.java file to that WEB-INF. After that I created a web.xml file like
------------------web.xml-------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
</web-app>
------------------------------------------------
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,
Qing


SCJP
Nikki Aniban
Greenhorn

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!
CoffeeFan
Greenhorn

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.
CoffeeFan
Greenhorn

Joined: Oct 11, 2002
Posts: 12
Hi,
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 CompressionFilter.java 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.
Qing
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.
/servlet/foo.bar
The container will look for the a servlet with classname: foo.bar
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: http://aspose.com/file-tools
 
subject: Servlet problem