Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application docx
Nội dung xem thử
Mô tả chi tiết
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:
ForestHashtable
12 Online Information Sources
A CDROM Contents
B Some Copyrights and Licenses
C Source Code for bonForum Web
Application
D Sun Microsystems, Inc. Binary
Code License Agreement
00 1089-9 FM 6/26/01 8:20 AM Page i
00 1089-9 FM 6/26/01 8:20 AM Page ii
XML, XSLT, Java
,
and JSP
:
A Case Study in
Developing a Web
Application
201 West 103rd Street, Indianapolis, Indiana 46290
An Imprint of Pearson Education
Boston • Indianapolis • London • Munich • New York • San Francisco
Westy Rockwell
www.newriders.com
00 1089-9 FM 6/26/01 8:20 AM Page iii
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
Larry Sweazy
Manufacturing
Coordinator
Jim Conway
Book Designer
Louisa Klucznik
Cover Designer
Aren Howell
Proofreader
Jeannie Smith
Composition
Gina Rexrode
XML, XSLT, Java, and JSP: A Case
Study in Developing a Web Application
Translation from the German language edition of: XML,
XSLT, Java, and JSP by Westy Rockwell 2000 Galileo Press
GmbH Bonn, Germany
FIRST EDITION: July 2001
All rights reserved. No part of this book may be reproduced
or transmitted in any form or by any means, electronic or
mechanical, including photocopying or recording, or by any
information storage and retrieval system, without written
permission from the publisher, except for the inclusion of
brief quotations in a review.
International Standard Book Number: 0-7357-1089-9
Library of Congress Catalog Card Number: 00-110885
05 04 03 02 01 7 6 5 4 3 2 1
Interpretation of the printing code:The rightmost doubledigit number is the year of the book’s printing; the rightmost 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 capitalized. 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 trademarks 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 warranty 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
❖
THIS BOOK IS DEDICATED
TO MEMORIES
OF YOU,
DON ROCKWELL, SR.
YOU GAVE SO MUCH TO ME!
DID I EVER SAY ENOUGH, SOMEHOW,
FOR YOU TO KNOW HOW MUCH I LOVE YOU?
WITHOUT YOUR LOVE AND KIND
GENEROSITY,
I WOULD NOT FEEL HALF SO FORTUNATE
TO BE ALIVE TODAY. BESIDES THAT,
YOU TAUGHT ME TO ENJOY THIS LIFE,
SWIM IN THE BLUE OCEANS,AND
DIVE DOWN SO DEEPLY.
I WOULD MISS YOU FOREVER,
IF I WERE NOT SO SURE
THAT YOU ARE
HERE.
THANK YOU!
W. R.
❖
00 1089-9 FM 6/26/01 8:20 AM Page v
TABLE OF CONTENTS
1 Introduction and
Requirements 1
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
3.5 Tomcat Examples of Servlets and
JSPs 49
3.6 Adding Your Tomcat Web
Application 49
3.7 Java Servlets and JSPs 53
3.8 The ServletConfig and
ServletContext Classes 57
3.9 Web Application Scopes 58
4 XML and XSLT: Xerces
and Xalan 61
4.1 Apache XML Project 61
4.2 Installing Xerces 62
4.3 Xerces Parses XML 64
4.4 SAX Sees XML as Events 67
4.5 Installing Xalan 67
4.6 Xalan Transforms XML Using
XSLT 70
4.7 Using Beanshell with Xalan 72
4.8 Using Xalan from the Command
Line 73
4.9 Zvon XSL Tutorial 73
4.10 Xerces and Xalan versus XT
and XP 73
4.11 JSP and XML Synergy 74
5 bonForum Chat Application:
Use and Design 77
5.1 Installing and Running
bonForum 77
5.2 Changing the bonForum Web
Application 83
5.3 Using XML to Design Web
Applications 86
5.4 XML Data Flows in Web
Applications 98
Contents vii
00 1089-9 FM 6/26/01 8:21 AM Page vii
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
8 Java Servlet and Java Bean:
BonForumEngine and
BonForumStore 189
8.1 The BonForumEngine
Servlet 189
8.2 The BonForumStore Class 262
9 Java Applet Plugged In:
BonForumRobot 285
9.1 Hands-on with Java Applets 285
9.2 XSLTProcessor Applet 290
9.3 BonForumRobot 290
viii Contents
00 1089-9 FM 6/26/01 8:21 AM Page viii
10 JSP Taglib:The bonForum
Custom Tags 303
10.1 Java Servlets, JSP, and Tag
Libraries 303
10.2 The bonForum Tag Library
316
10.3 The OutputDebugInfoTag
Class 324
10.4 The OutputPathNamesTag
Class 331
10.5 The OutputChatMessagesTag
Class 340
10.6 XSLT and the TransformTag
Class 352
10.7 Displaying the Available Chats
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
Contents ix
00 1089-9 FM 6/26/01 8:21 AM Page ix
11.10 More Public ForestHashtable
Methods 424
11.11 Initializing the bonForumXML
Database 427
11.12 Runtime bonForumXML
Database 429
11.13 More ForestHashtable
Considerations 432
12 Online Information
Sources 437
12.1 Always Useful Sites 437
12.2 Apache Software Foundation
438
12.3 Big Corporations 438
12.4 CSS 439
12.5 DOM Information 439
12.6 HTML 439
12.7 HTTP 439
12.8 Java 440
12.9 JavaServer Pages 441
12.10 Java Servlets 443
12.11 Linux 445
12.12 Open Source 445
12.13 RDF 446
12.14 Web Applications 446
12.15 Web Browsers 446
12.16 Web Servers 446
12.17 XML 447
12.18 XSL 452
A CD-ROM Contents 455
\Sun 456
\Apache 456
\bonForum 456
\tools 458
E-Book 458
x Contents
00 1089-9 FM 6/26/01 8:21 AM Page x
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
Contents xi
00 1089-9 FM 6/26/01 8:21 AM Page xi
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.
Westy has more than 15 years of experience as a professional software developer, but his involvement with computers dates back
longer yet. In 1965, he programmed the Pythagorean theorem into
an IBM 1620 with punched cards. His faculty adviser told him to
stop spending so much time on programming, which had no career
future. In 1970, while studying IBM 360 programming, he was considered too radical for saying that computers would one day play
chess. It was not until the early 1980s, with the arrival of microcomputers, that his career and his passion could merge.
His real software education came from deeply hacking many
microcomputers, including the ZX80, the Osborne, the Vic20, the
C64, various Amigas, and, of course, IBM PCs. His career, meanwhile, involved him with more respectable software and hardware,
including UNIX, workstations, minicomputers, mainframes, and, of
course, IBM PCs. Interest in hardware design, along with C and
assembly languages, culminated in 1994 when he built the prototype
for an extremely successful dual-processor alcohol analyser, including
the PCB design, operating system, and application software.
Soon afterward, while developing man-machine interfaces, the prerelease version of Borland Delphi turned Westy into a Windows
developer. He went on to work on three-tier systems based on
Windows NT, including corporate asset management, document
imaging, and work management systems. For more than a year now
he has refused to touch SQL or Visual tools, and he is enthusiastically
pursuing Web browser- and server-based applications using Java,
Tomcat, Xerces, and Xalan.
00 1089-9 FM 6/26/01 8:21 AM Page xii
xiii
About the Technical Reviewers
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 private 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 [email protected].
Perry Tew graduated from Georgia Institute of Technology with a degree in chemical 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.
Thanks are especially due to Elmar Geese, CEO of tarent GmbH, for making this
book possible.Also, Manfred Weltecke, for his masterful translation of the first book
version into German, to which it largely owes its success. Much credit for that success
also belongs to Harald Aberfeld, Michael Klink and Florian Hawlitzek, for their technical editing of the German edition.
00 1089-9 FM 6/26/01 8:21 AM Page xiii
xiv
Thanks to all my colleagues at tarent GmbH, for their selfless support of the book
project:Alex Steeg,Alexander Scharch, Boris Esser, Harald Aberfeld, Hendrik Helwich,
Kerstin Weber, Markus Heiliger, Martina Hundhausen, Matthias Esken, May-Britt
Baumann, Michael Klink, Robert Schuster,Thomas Mueller-Ackermann,Vanessa
Haering, and Vera Schwingenheuer. My absence from their projects while working on
this book created extra work for them; I appreciate that truly.
Thanks to the staff of Galileo Press, especially my editors Judith Stevens and
Corinna Stefani, for making the German edition happen. Others there whose work
on the book is appreciated are: proofreaders Claudia Falk and Hoger Schmidt, cover
designer Barbara Thoben, illustrator Leo Leowald, producer Petra Strauch, and computer typographer Joerg Gitzelmann.Thanks also to Petra Walther and Stefan
Krumbiegel of Galileo Press for supporting the German edition online.
Thanks to Lau Shih-Hor and Agnes Chin of Elixir Technologies, for adding value
to the CDROM.Thanks to the developers of TextPad, so useful for a technical writer.
Thanks to Jen Wilson for creating bonForum.links2go.com, in support of the book
project.
This book depends so much upon those who make the open source projects it and
its example project depend upon.Thanks to all involved with the Apache Software
Foundation, especially its Jakarta and Apache XML projects.Thanks also to the staff
and providers of SourceForge for making it a superb place to develop and learn about
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 editors, 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
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 better, what areas you’d like to see us publish in, and any other words of wisdom you’re
willing to pass our way.
As an Executive Editor at New Riders Publishing, I welcome your comments.You
can fax, email, or write me directly to let me know what you did or didn’t like about
this book—as well as what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book,
and that due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this book’s title and author, as well as
your name and phone or fax number. I will carefully review your comments and share
them with the author and editors who worked on the book.
Fax: 317-581-4663
Email: [email protected]
Mail: Stephanie Wall
Executive Editor
New Riders Publishing
201 West 103rd Street
Indianapolis, IN 46290 USA
00 1089-9 FM 6/26/01 8:21 AM Page xv