Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet problem

 
CoffeeFan
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nikki Aniban
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic