Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
XML, XSLT,
Java
, and JSP
:
A Case Study in
Developing a
Web Application
Contents At a Glance
1 Introduction and Requirements
2 An Environment for Java Software
Development
3 Java Servlets and JavaServer Pages:
Jakarta Tomcat
4 XML and XSLT: Xerces and Xalan
5 bonForum Chat Application: Use
and Design
6 bonForum Chat Application:
Implementation
7 JavaServer Pages:The Browseable
User Interface
8 Java Servlet and Java Bean:
BonForumEngine and
BonForumStore
9 Java Applet Plugged In:
BonForumRobot
10 JSP Taglib:The bonForum
Custom Tags
11 XML Data Storage Class:
•
New York
•
San Francisco
Westy Rockwell
www.newriders.com
00 1089-9 FM 6/26/01 8:20 AM Page iii
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Publisher
David Dwyer
Associate Publisher
Al Valvano
Executive Editor
Stephanie Wall
Managing Editor
Gina Brown
Product Marketing
Manager
Stephanie Layton
Publicity Manager
Susan Nixon
Software
Development
Specialist
Jay Payne
Project Editor
Elise Walter
Copy Editor
Krista Hansing
Indexer
05 04 03 02 01 7 6 5 4 3 2 1
Interpretation of the printing code:The rightmost double-
digit number is the year of the book’s printing; the right-
most single-digit number is the number of the book’s
printing. For example, the printing code 01-1 shows that the
first printing of the book occurred in 2001.
Composed in Bembo and MCPdigital by New Riders
Publishing
Printed in the United States of America
Trademarks
All terms mentioned in this book that are known to be
trademarks or service marks have been appropriately capital-
ized. New Riders Publishing cannot attest to the accuracy of
this information. Use of a term in this book should not be
regarded as affecting the validity of any trademark or service
mark. Java and JavaServer Pages (JSP) are registered trade-
marks of Sun Microsystems, Inc.
Warning and Disclaimer
This book is designed to provide information about XML,
XSLT, Java, and JSP. Every effort has been made to make this
book as complete and as accurate as possible, but no war-
ranty or fitness is implied.
The information is provided on an as-is basis.The authors
and New Riders Publishing shall have neither liability nor
responsibility to any person or entity with respect to any loss
or damages arising from the information contained in this
book or from the use of the discs or programs that may
accompany it.
00 1089-9 FM 6/26/01 8:20 AM Page iv
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
1.1 The Goal of This Book 1
1.2 Why Use This Book? 2
1.3 How to Use This Book 4
1.4 Some Choices Facing Web
Application Developers 6
1.5 Development Choices Made for
This Book 8
1.6 A Note About Platform
Independence 14
2 An Environment for
Java Software
Development 15
2.1 Java 2 Platform,
Standard Edition 15
2.2 Compiling Java Programs 19
2.3 Running Java Programs 30
2.4 Debugging Java Programs 32
2.5 Other Features of ElixirIDE 33
3 Java Servlets and
JavaServer Pages:
Jakarta Tomcat 35
3.1 Apache Software
Foundation 35
3.2 Jakarta Tomcat 36
3.3 Installing Tomcat 37
3.4 Running Tomcat 39
00 1089-9 FM 6/26/01 8:21 AM Page vi
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
3.5 Tomcat Examples of Servlets and
JSPs 49
5.4 XML Data Flows in Web
Applications 98
vii
Contents
00 1089-9 FM 6/26/01 8:21 AM Page vii
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
6 bonForum Chat Application:
Implementation 103
6.1 Building the bonForum Web
Chat 103
6.2 Displaying and Selecting Chat
Subjects 138
6.3 Displaying Chat Messages 140
6.4 Finding the Chat Element 146
6.5 Displaying and Selecting Chats
148
6.6 Displaying Guests in Chat 150
6.7 Outputting the bonForum Data
as XML 150
6.8 Future of bonForum Project
151
7 JavaServer Pages: The
Browseable User
Interface 155
7.1 JSP-Based Web Applications
155
7.2 Viewing bonForum from Its JSP
Documents 163
7.3 Further Discussion About the JSP
in bonForum 187
371
10.8 Displaying the Available
bonForums 376
10.9 Displaying the Guests
in a Chat 379
11 XML Data Storage Class:
ForestHashtable 385
11.1 Overview of bonForum Data
Storage 385
11.2 The NodeKey Class 387
11.3 The BonNode Class 388
11.4 ForestHashtable Maps Data
Trees 390
11.5 Caching Keys for Fast Node
Access 398
11.6 Adding ForestHashtable Nodes
404
11.7 Deleting ForestHashtable Nodes
411
11.8 Editing ForestHashtable Nodes
414
11.9 Getting ForestHashtable as
XML 416
ix
Contents
00 1089-9 FM 6/26/01 8:21 AM Page ix
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
11.10 More Public ForestHashtable
Methods 424
11.11 Initializing the bonForumXML
\tools 458
E-Book 458
x
Contents
00 1089-9 FM 6/26/01 8:21 AM Page x
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
B Some Copyrights
and Licenses 459
BonForum License 459
Apache Xerces License 460
Apache Xalan License 461
Jakarta Tomcat License 462
C Source Code for
bonForum Web
Application 465
D Sun Microsystems, Inc.
Binary Code License
Agreement 703
Index
xi
Contents
00 1089-9 FM 6/26/01 8:21 AM Page xi
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xii
About the Author
Westy Rockwell considers himself a world citizen. Currently he is a
senior developer at tarent GmbH, a Web development company in
Bonn, Germany. His greatest pleasure is enjoying the company of his
wife, Zamina, and their two daughters, Joaquina and Jennifer.
Somehow, they tolerate his intense involvement with computers.
These reviewers contributed their considerable hands-on expertise to the entire
development process for XML, XSLT, Java, and JSP: A Case Study in Developing a Web
Application. As the book was being written, these dedicated professionals reviewed all
the material for technical content, organization, and flow.Their feedback was critical
to ensuring that XML, XSLT, Java, and JSP: A Case Study in Developing a Web
Application fits our reader’s need for the highest-quality technical information.
Brad Irby holds a bachelor of computer science degree from the University of
North Carolina, and he has been a programmer and system designer since 1985. He
has worked with many different languages and databases over the years, but he now
specializes in application development using a Microsoft SQL Server back end. A pri-
vate consultant for eight years, Brad has been following the progress of the W3C and
the XML specification since its inception, and he has done extensive work using the
XML extensions of SQL Server to transfer data over secure internet links. He can be
reached at
.
Perry Tew graduated from Georgia Institute of Technology with a degree in chemi-
cal engineering, but he has since fallen in love with computer programming. Perry
began his IT career as a MCSD and currently programs with Java. He works as an
integration specialist for a major contact lens producer. He spends his free time with
his wife, Paula, basking in they joy of parenthood brought by the arrival of their
newborn, Joshua.
Acknowledgments
Most of all, I want to thank Jennifer, Joaquina and Zamina Rockwell, who are the real
treasures in my life.Without their love, understanding, playfulness and patience this
book could never have been written.
There are so many others to thank, I know I will omit some here: those who
toiled behind the scenes, those who taught me, worked with me, helped me come to
this point in my professional career. If you are one of these, I would like to thank you
as well. Please forgive the unintentional omission of your name.
open source software.Thanks to Sun for making its JDK available for learning Java.
Many thanks to the staff of New Riders who made the English version of the
book happen. Especially to Stephanie Wall (Executive Editor), who went way beyond
the call of duty to keep the book alive until publication, and to Elise Walter (Project
Editor), who always kept her good humor no matter how late my requests for changes
came to her.The book was vastly improved by the “no-holds-barred” technical edi-
tors, including Brad Irby, Erin Mulder, and Perry Tew.Thanks to Jay Payne (Media
Developer), who produced the CD-ROM.After working with words for over a year
myself, I know I owe so much of this book’s existence to Krista Hansing (Copy
Editor), Larry Sweazy (Indexer), Gina Rexrode (Compositor).Thanks also to Susan
Nixon (Public Relations).
Thanks to Jeffrey E. Northridge, whose friendship and partnership-in-programming
has been so valued by me.Thanks to Jaime del Palacio, a superb software developer
(and nephew).Thanks to PhoenixFire, for giving me that first, all-important chance as
a professional software developer (If you read this, please contact me!).Thanks to John
Haefeli of ISI, who provided so many difficult real-world problems to solve with C.
Thanks to Alvaro Pastor, Glenn Forrester, and all the gang who were at Intoximeters
West, especially to Doug, Iza, Petcy who helped so much to develop me as a software
developer.Thanks to Paul McEvoy for his mentoring and my appreciation of cafe
latte.Thanks to Elliot Mehrbach for helping me learn SQL and Delphi.
Finally, I would like to thank especially Daph, Cita and Marcos Rockwell, and all
my other relatives, for their unconditional love.Thanks also to Nature and Life, for
their unconditional and priceless support.
00 1089-9 FM 6/26/01 8:21 AM Page xiv
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xv
Tell Us What You Think
As the reader of this book, you are the most important critic and commentator.We
value your opinion and want to know what we’re doing right, what we could do bet-
ter, what areas you’d like to see us publish in, and any other words of wisdom you’re
and paraphrase them, and, presto! A book is born, ready to meet the market demand.
Especially in the field of software development, many books seem to have been writ-
ten in this way.
When I was asked to write a book about Web application development with XML
and Java, I replied that the book would have to be a practical “how-to” manual, based
upon real development experiences. Its target audience would be software developers
trying to understand and harness those technologies. I knew that to write that book, I
would have to “cook the meal” myself. My fundamental task would be to develop a
functional and timely Web application project, of at least plausible utility.
Surfing the Web, I soon gathered very much information. I determined which of all
the available tools and products this book would feature. Most of them were then in a
state of flux, and all are still evolving. In fact, a worldwide effort is continually imple-
menting products based on ever-evolving tools and standards related to XML and Java.
Even for an experienced software developer, putting all this information and tech-
nology to practical use was no simple task. Many of the well-documented tools were
obsolete, and the more current tools were often not well documented. Extremely
active mailing lists were frequented by early adopters building real Web applications;
these pioneers often faced with incompatibilities between the tools and the standards.
At first, my plan was to complete the earlier chapters, which present the tools and
technologies, and then to develop the book project and write the later chapters. It
soon became clear that this would put the cart before the horse. I decided to first cre-
ate the Web application and only then, always in the context of that project, to discuss
how XML and Java-based technologies could be applied by the reader.
That is when the fun started. I designed and implemented a Web chat application
called bonForum. It is based on XML and XSLT, Java servlets and applets, and JSP. It
presented me with many of the most challenging tasks of Web application design. As a
very popular and timely type of Web application, I trust that it will interest the reader.
As an experiment and a tutorial, its design and implementation provide a framework
for ongoing development by the readers of this book. It can and should morph into
other types of Web applications besides a chat room.
bonForum, the Web chat application that will be the major subject of the rest of the
book. It was designed as a tool to explore each of the subjects of this book, XML,
XSLT, Java Servlets, Java Applets and JavaServer Pages, while solving some real Web
application problems.
Chapter 6,“BonForum Chat Application: Implementation,” continues the overview
of bonForum that began in Chapter 5. Some tougher implementation problems are
also highlighted, and suggestions for future development of the Web chat are given.
Chapter 7,“Java Servlet and Java Bean: BonForum Engine and bon Forum Store,”
teaches the JSP technology that the Tomcat Server supports, as JavaServer Pages are
used to create a BUI, a browseable user interface, for our Web application.
Chapter 8,“Java Servlet in Charge: BonForumEngine,” describes the central class in
the bonForum Web application. It also illustrates some themes common to using Java
Servlets in Web applications.
Chapter 9,“Java Applet Plugged In: BonForumRobot,” discusses the
bonForumRobot applet, which is part of the bonForum Web chat application.This
chapter teaches how to create and deploy a Java Applet to control a Web application
user interface and use Sun Java Plug-in to support an Applet on the client.
00 1089-9 FM 6/26/01 8:21 AM Page xvii
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xviii
Chapter 10,“JSP Taglib:The bonForum Custom Tags,” explains how to use a JSP
Tag Library with the bonForum Web application. All the functions that are included in
the multi-purpose ChoiceTag are discussed, which are used on many of the JSP docu-
ments in the Web chat example.This chapter also shows you how the Apache Xalan
XSLT processor is used from the custom tag.
Chapter 11,“XML Data Storage Class: ForestHashtable,” shows how data storage
for the XML data in the bonForum chat application is implemented.This chapter also
teaches how to add a few tricks to a descendant of the Hashtable class to optimize
XML element retrieval and simulate a database program design.
Chapter 12,“Online Information Sources,” provides links to XML, XSLT, Java
Windows 95, 98, or 2000 instead.With a bit more effort, an experienced developer
could use much of the material in this book with a Linux or UNIX operating
01 1089-9 CH01 6/26/01 7:24 AM Page 1
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.