This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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
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.
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
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
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!