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.
All the servlets mentioned here are examples from Marty Hall's "Core Servlets and JavaServer Pages". I was able to get the HelloWWW2 servlet and SnoopServlet to run properly. But when I tried to compile HelloWWW3 or LotteryNumbers servlets, I encountered an error in both cases: undefined variable or class name: ServletUtilities I was able to compile ServletUtilities.java and the class file was in the proper folder. I do not understand why I can't get the servlets which call the ServletUtilities.headWithTitle("") method to work. All these servlets do is call a static method in a public class. Does anybody have any idea what is happening? Thanks a lot! Xinbo
Joined: Jan 05, 2001
I'd like to add that my problem appears to be a result of the fact that Both HelloWWW3.java and ServletUtilities.java belongs to the coreservlets package. If I comment out package coreservlets in both .java files and set the classpath properly, I can compile and run the HelloWWW3 servlet with no problem. More details, I have a Myservletc.bat file (see below) sitting in C:\Windows\command. and my servlet .java files( all belong to coreservlets package) are in C:\MyServlets\coreservlets. here is how I compile: C:\MyServlets\coreservlets>Myservletc HelloWWW3.java Here I have an error message: undefined variable or class name: ServletUtilities (Note HelloWWW3.java calls ServletUtilities.method(), the later is a static method.) I may be asking a very simple question: How do I set the classpath so I can compile all related .java files belong to the same package? Your help is greatly appreciated! ---------------------------------------------------- Myservletc.bat @echo off rem This is the version for the Tomcat server set CLASSPATH=C:\tomcat\lib\servlet.jar; C:\tomcat\lib\jasper.jar; C:\MyServlets;C:\MyServlets\ChengServlets;%CLASSPATH% C:\jdk1.2\bin\javac -d C:\tomcat\webapps\ROOT\WEB-INF\classes %1% rem last line is just to deposit .class file in ...\classes rem folder.