Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
30
Chapter 2 First Servlets
and the JSP JAR file. On Windows NT or Windows 2000, you go to the Start
menu, select Settings, select Control Panel, select System, select Environment,
then enter the variable and value. On Unix (C shell), you set the 
CLASSPATH
variable by
setenv CLASSPATH /install_dir/servlets:$CLASSPATH
Put this in your 
.cshrc
 file to make it permanent. 
If your package were of the form 
name1.name2.name3
 rather than simply
name1
 as here, the 
CLASSPATH
 should still point to the top level servlet direc 
tory, that is, the directory containing 
name1
. 
A second way to compile classes that are in packages is to keep the source
code in a location distinct from the class files. First, you put your package direc 
tories in any location you find convenient. The 
CLASSPATH
 refers to this loca 
tion. Second, you use the 
 d
 option of 
javac
 to install the class files in the
directory the Web server expects. An example follows. Again, you will probably
want to set the 
CLASSPATH
 permanently rather than set it each time.
DOS> cd C:\MyServlets\coreservlets
DOS> set CLASSPATH=C:\MyServlets;%CLASSPATH%
DOS> javac  d C:\tomcat\webpages\WEB INF\classes HelloWWW2.java
Keeping the source code separate from the class files is the approach I use
for my own development. To complicate my life further, I have a number of
different 
CLASSPATH
 settings that I use for different projects, and typically
use JDK 1.2, not JDK 1.1 as the Java Web Server expects. So, on Windows I
find it convenient to automate the servlet compilation process with a batch
file 
servletc.bat
, as shown in Listing 2.5 (line breaks in the 
set CLASS 
PATH
 line inserted only for readability). I put this batch file in 
C:\Win 
dows\Command
 or somewhere else in the Windows 
PATH
. After this, to
compile the 
HelloWWW2
 servlet and install it with the Java Web Server, I
merely go to 
C:\MyServlets\coreservlets
 and do  
servletc
HelloWWW2.java
 . The source code archive at 
http://www.coreserv 
lets.com/
 contains variations of 
servletc.bat
 for the JSWDK and Tom 
cat. You can do something similar on Unix with a shell script. 
Invoking Servlets in Packages
To invoke a servlet that is in a package, use the URL 
http://host/servlet/packageName.ServletName
instead of 
http://host/servlet/ServletName
Thus, if the Web server is running on the local system, 
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved