Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
28
Chapter 2 First Servlets
Figure 2 2
Result of Listing 2.3 (HelloWWW.java).
and the way they're invoked. Let's take these areas one at a time in the follow
ing three subsections. The first two changes are exactly the same as with any
other Java class that uses packages; there is nothing specific to servlets.
Creating Servlets in Packages
Two steps are needed to place servlets in packages:
1. Move the files to a subdirectory that matches the
intended package name.
For example, I'll use the
coreservlets
package for most of the
rest of the servlets in this book. So, the class files need to go in a
subdirectory called
coreservlets
.
2. Insert a package statement in the class file.
For example, to place a class file in a package called
somePack
age
, the first line of the file should read
package somePackage;
For example, Listing 2.4 presents a variation of the
HelloWWW
servlet that is in the
coreservlets
package. The class file goes in
install_dir/webpages/WEB INF/classes/coreservlets
for Tomcat
3.0, in
install_dir/webpages/WEB INF/servlets/coreservlets
for
the JSWDK 1.0.1, and in
install_dir/servlets/coreservlets
for the
Java Web Server 2.0.
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
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