XML, XSLT, A Case Study in Developing a Web Application Contents At a Glance 1 Introduction and Requirements 2 An Environment for Java SoftwareDevelopment 3 Java Servlets and JavaServer
Trang 2XML, XSLT,
A Case Study in Developing a Web Application
Contents At a Glance
1 Introduction and Requirements
2 An Environment for Java SoftwareDevelopment
3 Java Servlets and JavaServer Pages:Jakarta Tomcat
4 XML and XSLT: Xerces and Xalan
5 bonForum Chat Application: Useand Design
6 bonForum Chat Application:Implementation
7 JavaServer Pages:The BrowseableUser Interface
8 Java Servlet and Java Bean:
BonForumEngine andBonForumStore
9 Java Applet Plugged In:
BonForumRobot
10 JSP Taglib:The bonForumCustom Tags
11 XML Data Storage Class:
ForestHashtable
12 Online Information Sources
B Some Copyrights and Licenses
C Source Code for bonForum WebApplication
D Sun Microsystems, Inc BinaryCode License Agreement
Trang 4XML, XSLT, Java ,
A Case Study in Developing a Web Application
201 West 103rd Street, Indianapolis, Indiana 46290
An Imprint of Pearson EducationBoston • Indianapolis •London •Munich •New York •San Francisco Westy Rockwell
www.newriders.com
Trang 5Stephanie Layton
Publicity Manager
Susan Nixon
Software Development Specialist
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 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.
Trang 6THIS 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.
❖
Trang 7T ABLE OF C ONTENTS
1 Introduction and Requirements 1
1.1 The Goal of This Book 11.2 Why Use This Book? 21.3 How to Use This Book 41.4 Some Choices Facing WebApplication Developers 61.5 Development Choices Made forThis Book 8
1.6 A Note About PlatformIndependence 14
2 An Environment for Java Software
Development 15
2.1 Java 2 Platform,Standard Edition 152.2 Compiling Java Programs 192.3 Running Java Programs 302.4 Debugging Java Programs 322.5 Other Features of ElixirIDE 33
3 Java Servlets and JavaServer Pages:
Jakarta Tomcat 35
3.1 Apache Software Foundation 353.2 Jakarta Tomcat 363.3 Installing Tomcat 373.4 Running Tomcat 39
Trang 83.5 Tomcat Examples of Servlets andJSPs 49
3.6 Adding Your Tomcat WebApplication 49
3.7 Java Servlets and JSPs 533.8 The ServletConfig andServletContext Classes 573.9 Web Application Scopes 58
4 XML and XSLT: Xerces and Xalan 61
4.1 Apache XML Project 614.2 Installing Xerces 624.3 Xerces Parses XML 644.4 SAX Sees XML as Events 674.5 Installing Xalan 67
4.6 Xalan Transforms XML UsingXSLT 70
4.7 Using Beanshell with Xalan 724.8 Using Xalan from the CommandLine 73
4.9 Zvon XSL Tutorial 734.10 Xerces and Xalan versus XTand XP 73
4.11 JSP and XML Synergy 74
5 bonForum Chat Application:
Use and Design 77
5.1 Installing and RunningbonForum 775.2 Changing the bonForum WebApplication 83
5.3 Using XML to Design WebApplications 86
5.4 XML Data Flows in WebApplications 98
vii
Contents
Trang 96 bonForum Chat Application:
6.6 Displaying Guests in Chat 1506.7 Outputting the bonForum Data
as XML 1506.8 Future of bonForum Project151
7 JavaServer Pages: The Browseable User Interface 155
7.1 JSP-Based Web Applications155
7.2 Viewing bonForum from Its JSPDocuments 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 2859.2 XSLTProcessor Applet 2909.3 BonForumRobot 290
Trang 1010 JSP Taglib: The bonForum Custom Tags 303
10.1 Java Servlets, JSP, and TagLibraries 303
10.2 The bonForum Tag Library316
10.3 The OutputDebugInfoTagClass 324
10.4 The OutputPathNamesTagClass 331
10.5 The OutputChatMessagesTagClass 340
10.6 XSLT and the TransformTagClass 352
10.7 Displaying the Available Chats371
10.8 Displaying the AvailablebonForums 37610.9 Displaying the Guests
11.5 Caching Keys for Fast NodeAccess 398
11.6 Adding ForestHashtable Nodes404
11.7 Deleting ForestHashtable Nodes411
11.8 Editing ForestHashtable Nodes414
11.9 Getting ForestHashtable asXML 416
ix
Contents
Trang 1111.10 More Public ForestHashtableMethods 424
11.11 Initializing the bonForumXMLDatabase 427
11.12 Runtime bonForumXMLDatabase 429
11.13 More ForestHashtableConsiderations 432
12 Online Information Sources 437
12.1 Always Useful Sites 43712.2 Apache Software Foundation438
12.3 Big Corporations 43812.4 CSS 439
12.5 DOM Information 43912.6 HTML 439
12.7 HTTP 43912.8 Java 44012.9 JavaServer Pages 44112.10 Java Servlets 44312.11 Linux 44512.12 Open Source 44512.13 RDF 44612.14 Web Applications 44612.15 Web Browsers 44612.16 Web Servers 44612.17 XML 44712.18 XSL 452
Trang 12B Some Copyrights and Licenses 459
BonForum License 459Apache Xerces License 460Apache Xalan License 461Jakarta Tomcat License 462
C Source Code for bonForum Web Application 465
D Sun Microsystems, Inc.
Binary Code License Agreement 703 Index
xi
Contents
Trang 13About the Author
Westy Rockwellconsiders himself a world citizen Currently he is asenior developer at tarent GmbH, a Web development company inBonn, Germany His greatest pleasure is enjoying the company of hiswife, 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 soft-ware developer, but his involvement with computers dates backlonger yet In 1965, he programmed the Pythagorean theorem into
an IBM 1620 with punched cards His faculty adviser told him tostop spending so much time on programming, which had no careerfuture In 1970, while studying IBM 360 programming, he was con-sidered too radical for saying that computers would one day playchess It was not until the early 1980s, with the arrival of micro-computers, that his career and his passion could merge
His real software education came from deeply hacking manymicrocomputers, including the ZX80, the Osborne, the Vic20, theC64, various Amigas, and, of course, IBM PCs His career, mean-while, involved him with more respectable software and hardware,including UNIX, workstations, minicomputers, mainframes, and, ofcourse, IBM PCs Interest in hardware design, along with C andassembly languages, culminated in 1994 when he built the prototypefor an extremely successful dual-processor alcohol analyser, includingthe PCB design, operating system, and application software
Soon afterward, while developing man-machine interfaces, the release version of Borland Delphi turned Westy into a Windowsdeveloper He went on to work on three-tier systems based onWindows NT, including corporate asset management, documentimaging, and work management systems For more than a year now
pre-he has refused to touch SQL or Visual tools, and pre-he is enthusiasticallypursuing Web browser- and server-based applications using Java,Tomcat, Xerces, and Xalan
Trang 14About 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 Irbyholds a bachelor of computer science degree from the University ofNorth Carolina, and he has been a programmer and system designer since 1985 Hehas worked with many different languages and databases over the years, but he nowspecializes 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 andthe XML specification since its inception, and he has done extensive work using theXML extensions of SQL Server to transfer data over secure internet links He can bereached at Brad@BradIrby.com
Perry Tewgraduated from Georgia Institute of Technology with a degree in cal engineering, but he has since fallen in love with computer programming Perrybegan his IT career as a MCSD and currently programs with Java He works as anintegration specialist for a major contact lens producer He spends his free time withhis wife, Paula, basking in they joy of parenthood brought by the arrival of their newborn, Joshua
chemi-Acknowledgments
Most of all, I want to thank Jennifer, Joaquina and Zamina Rockwell, who are the realtreasures in my life.Without their love, understanding, playfulness and patience thisbook could never have been written
There are so many others to thank, I know I will omit some here: those whotoiled behind the scenes, those who taught me, worked with me, helped me come tothis 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 thisbook possible Also, Manfred Weltecke, for his masterful translation of the first bookversion into German, to which it largely owes its success Much credit for that successalso belongs to Harald Aberfeld, Michael Klink and Florian Hawlitzek, for their tech-nical editing of the German edition
Trang 15Thanks to all my colleagues at tarent GmbH, for their selfless support of the bookproject: Alex Steeg, Alexander Scharch, Boris Esser, Harald Aberfeld, Hendrik Helwich,Kerstin Weber, Markus Heiliger, Martina Hundhausen, Matthias Esken, May-BrittBaumann, Michael Klink, Robert Schuster,Thomas Mueller-Ackermann,VanessaHaering, and Vera Schwingenheuer My absence from their projects while working onthis book created extra work for them; I appreciate that truly.
Thanks to the staff of Galileo Press, especially my editors Judith Stevens andCorinna Stefani, for making the German edition happen Others there whose work
on the book is appreciated are: proofreaders Claudia Falk and Hoger Schmidt, coverdesigner Barbara Thoben, illustrator Leo Leowald, producer Petra Strauch, and com-puter typographer Joerg Gitzelmann.Thanks also to Petra Walther and StefanKrumbiegel 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 bookproject
This book depends so much upon those who make the open source projects it andits example project depend upon.Thanks to all involved with the Apache SoftwareFoundation, especially its Jakarta and Apache XML projects.Thanks also to the staffand providers of SourceForge for making it a superb place to develop and learn aboutopen 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 thebook happen Especially to Stephanie Wall (Executive Editor), who went way beyondthe call of duty to keep the book alive until publication, and to Elise Walter (ProjectEditor), who always kept her good humor no matter how late my requests for changescame 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 (MediaDeveloper), who produced the CD-ROM After working with words for over a yearmyself, I know I owe so much of this book’s existence to Krista Hansing (CopyEditor), Larry Sweazy (Indexer), Gina Rexrode (Compositor).Thanks also to SusanNixon (Public Relations)
Thanks to Jeffrey E Northridge, whose friendship and partnership-in-programminghas 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 JohnHaefeli 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 IntoximetersWest, especially to Doug, Iza, Petcy who helped so much to develop me as a softwaredeveloper.Thanks to Paul McEvoy for his mentoring and my appreciation of cafelatte.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, fortheir unconditional and priceless support
Trang 16Tell Us What You Think
As the reader of this book, you are the most important critic and commentator.Wevalue 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’rewilling to pass our way
As an Executive Editor at New Riders Publishing, I welcome your comments.Youcan fax, email, or write me directly to let me know what you did or didn’t like aboutthis 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 asyour name and phone or fax number I will carefully review your comments and sharethem with the author and editors who worked on the book
Fax: 317-581-4663Email: stephanie.wall@newriders.com
Mail: Stephanie Wall
Executive EditorNew Riders Publishing
201 West 103rd StreetIndianapolis, IN 46290 USA
Trang 17For more than 20 years, I have read books about software development Many of theserepeated information available to me elsewhere Formerly, that information was oftenfrom magazines; recently its source is the Internet A few books, refreshingly, werebased instead upon the authors’ “hands on” experiences with the art and science ofsoftware development
You can now write a book about how to become a gourmet chef without everhaving cooked a meal Simply download a collection of recipes from the Web, organizeand 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 XMLand Java, I replied that the book would have to be a practical “how-to” manual, basedupon real development experiences Its target audience would be software developerstrying to understand and harness those technologies I knew that to write that book, Iwould have to “cook the meal” myself My fundamental task would be to develop afunctional and timely Web application project, of at least plausible utility
Surfing the Web, I soon gathered very much information I determined which of allthe available tools and products this book would feature Most of them were then in astate 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 wereobsolete, and the more current tools were often not well documented Extremelyactive 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 andtechnologies, and then to develop the book project and write the later chapters Itsoon 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 discusshow XML and Java-based technologies could be applied by the reader
That is when the fun started I designed and implemented a Web chat applicationcalled bonForum It is based on XML and XSLT, Java servlets and applets, and JSP Itpresented me with many of the most challenging tasks of Web application design As avery 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 frameworkfor ongoing development by the readers of this book It can and should morph intoother types of Web applications besides a chat room
I welcome bug reports, fixes, suggestions, feedback, and communication! Pleasecontact me at mail@bonforum.org Look for errata, version updates, mailing lists, andrelated information at http://www.bonforum.org
Trang 18Conventions Used in This Book
Monospaced fontis used to indicate code, including commands, options, objects, and
so on It is also used for Internet addresses Italics are used to introduce and define a
new term Code continuation characters are used in code listings that are too long tofit within the book’s margins.They should not be used in actual implementation
How This Book Is Organized
This book is organized so that you can easily follow along with the case study andbuild the Web chat application along with the author and his team Each chapterbuilds on the previous one
Chapter 1, “Introduction and Requirements,” explains the goal of writing thisbook It also describes why certain tools were selected for the project
Chapter 2, “An Environment for Java Software Development,” teaches you how toset up an inexpensive Java development environment It shows you how to compile,debug and run the Web application example project
Chapter 3, “Java Servlets and JavaServer Pages: Jakarta Tomcat,” introduces Tomcat,which is an HTTP server and a container for Java Servlets and JavaServer Pages.Chapter 4, “XML and XSLT: Xerces and Xalan,” introduces Xerces, a DOM and aSAX parser, and Xalan, an XSLT and XPATH processor
Chapter 5, “BonForum Chat Application: Use and Design,” introduces you tobonForum, the Web chat application that will be the major subject of the rest of thebook 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 Webapplication problems
Chapter 6, “BonForum Chat Application: Implementation,” continues the overview
of bonForum that began in Chapter 5 Some tougher implementation problems arealso 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 areused to create a BUI, a browseable user interface, for our Web application
Chapter 8, “Java Servlet in Charge: BonForumEngine,” describes the central class inthe bonForum Web application It also illustrates some themes common to using JavaServlets in Web applications
Chapter 9, “Java Applet Plugged In: BonForumRobot,” discusses thebonForumRobot applet, which is part of the bonForum Web chat application.Thischapter teaches how to create and deploy a Java Applet to control a Web applicationuser interface and use Sun Java Plug-in to support an Applet on the client
Trang 19Chapter 10, “JSP Taglib:The bonForum Custom Tags,” explains how to use a JSPTag Library with the bonForum Web application All the functions that are included inthe 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 XalanXSLT processor is used from the custom tag
Chapter 11, “XML Data Storage Class: ForestHashtable,” shows how data storagefor the XML data in the bonForum chat application is implemented.This chapter alsoteaches how to add a few tricks to a descendant of the Hashtable class to optimizeXML element retrieval and simulate a database program design
Chapter 12, “Online Information Sources,” provides links to XML, XSLT, JavaServlet and JSP information
Appendices A and B provide the CD-ROM contents and copyright information.The project’s source code is listed in Appendix C
An added note: when the author uses the term “we” throughout the book, he isreferring to the team that worked on the bonForum Web application
Trang 20Introduction and Requirements
1
IN THIS CHAPTER,YOU FIND OUT WHATwe want this book to provide.We also sent the choices made to support the “practical” side of the book Here we try to jus-tify the software tools and libraries that we selected to illustrate a large subject:developing Web applications powered by XML, XSLT, Java servlets, Java applets, andJavaServer Pages
pre-1.1 The Goal of This Book
While writing this book, we have assumed that you, its reader, are a software developerwith some Java experience and that you want to build Web applications based onXML, XSLT, Java servlets, Java applets, and JavaServer Pages.The goal of this book is tosupport you as you learn about using all of these increasingly important technologiestogether.This book will help you become familiar with a set of widely available andprofessional software tools that covers all these technologies Furthermore, it will intro-duce you to many of the tasks that you will encounter in your own projects, by tack-ling these tasks within the context of a realistically large example project: a Webapplication named bonForum
The examples and the Web application project for this book were developed on a
PC using Windows NT 4.0 If you prefer, you can use this book together withWindows 95, 98, or 2000 instead.With a bit more effort, an experienced developercould use much of the material in this book with a Linux or UNIX operating
Trang 21system—we have tried to minimize any platform dependencies both in the codeexamples and in the case study.
Except for using Windows NT 4.0 as our operating system, we have preferred tofeature freely available, platform-independent, open-source software technologies.Nevertheless, the technologies and tools that we have chosen are among the mostpopular ones currently in use by XML and Web application developers
We do not intend this book to be a complete reference to XML, XSLT, Javaservlets, Java applets, or JSP Nor do we intend it to be an introduction to these topics.However, if you are an aspiring Web application developer who is new to XML tech-nologies or new to Java server-side technologies, you can start the book with Chapter
12, “Online Information Sources.” By using the many Web links there, you can findeverything that is needed to understand the material in this book
1.2 Why Use This Book?
The popularity of the Extensible Markup Language (XML) and Java server-side ware technologies (servlets and JSP) is exploding as developers become aware of theirpower and purpose One result is that books on these subjects are growing in number
soft-and are being translated into many languages For example, Steve Holzner’s Inside
XML, published by New Riders (ISBN: 0-7357-1020-1), is selling extremely well.The
excellent book Core Servlets and JavaServer Pages, by Marty Hall (ISBN:
0-1308-9340-4) and published by Prentice Hall PTR/Sun Microsystems Press, will be translatedinto at least eight languages from its original English.We could give many additionalexamples of similar books.There is something behind this popularity: XML, XSLT,Java servlets, and JavaServer Pages are quite well established in professional softwaredevelopment.They’ve now been around long enough to become extremely useful inreal projects
They are also evolving rapidly, which is illustrated by the release dates of theirrelated proposals and recommendations published by the W3C (The World Wide WebConsortium, an official standards body for Web technologies.) Consider some datesrelated to XML technologies On February 10, 1998, the XML 1.0 specificationbecame a recommendation of the W3C.The second edition of the specification isdated October 6, 2000 XSL was submitted as a proposal to the W3C on August 27,1997.Version 1.0 of XSL Transformations (XSLT) is dated November 16, 1999.Version1.0 of XSL was a candidate for official W3C recommendation by November 21, 2000.Now consider some dates related to Java server-side Web technologies.The
JavaServer Pages 0.092 specification is dated October 1998 JSP 1.0 was publiclyreleased in June 1999 JSP 1.1, which is featured in this book, is from spring 2000 By
a now robust and useful Web technology, it is based upon the Java Servlets API 2.1,which dates from April 1999
The fast evolution of these technologies is being driven by their usefulness in thedevelopment of Web applications Of course, you know how crucial the role of
Trang 221.2 Why Use This Book?
HTML has been (and still is) within the World Wide Web.The following is a quotefrom the XML FAQ (http://www.ucc.ie/xml/), which suggests one reason for theincreasing importance of XML:
HTML is already overburdened with dozens of interesting but incompatible tions from different manufacturers because it provides only one way of describingyour information
inven-XML allows groups of people or organizations to create their own customizedmarkup applications for exchanging information in their domain (music, chemistry,electronics, hill-walking, finance, surfing, petroleum geology, linguistics, cooking,knitting, stellar cartography, history, engineering, rabbit-keeping, mathematics,
etcætera ad infinitum).
HTML is at the limit of its usefulness as a way of describing information, and while
it will continue to play an important role for the content it currently represents,many new applications require a more robust and flexible infrastructure
If XML is a better way of describing information (and it is), then XSLT is a betterway of transforming that information from one description to another.When used totransform data into HTML, the power of XSLT becomes particularly useful in Webapplications, which rely on HTML browsers for their visual presentation to a user
Now take a look at some quotes from the Sun press release announcing JSP 1.0:
Sun announces the immediate availability of JavaServer Pages technology, which forthe first time allows Web page developers to easily build cross-platform, truly inter-active Web sites
Harnessing the full power of the Java platform, JavaServer Pages technology rates the functions of content generation and page layout, providing developerswith a simplified and more efficient way to create server-generated Web pages thatcombine content from a wide variety of enterprise data sources Because JavaServerPages technology encapsulates much of the functionality required to generate
sepa-“dynamic,” or constantly changing, content,Web page developers can concentrate
on the “look” and display of the site without the need for application developmentexpertise
These are big promises It is because they are more than just promises that JSP isincreasingly popular.These paragraphs of PR are, in fact, a quite accurate description
of JSP For a good overall view of the increasing popularity of JSP (and servlets), visitthe Industry Momentum page for JSP at Sun, at http://java.sun.com/products/jsp/
industry.html.The popularity of JSP and Java servlet technologies is also illustrated by the factthat more than a million downloads of Tomcat, an open-source server for Java servletsand JavaServer Pages, had occurred by the year 2001.The number of downloads of thecurrent Java 2 software development kit from Sun (Java 2 SDK) will no doubt surpassfive million by the time you are reading this All these downloads are votes for theimportance of the technologies central to our book
Trang 23This might convince you of the importance of the technologies that appear in thetitle of this book, if you were not convinced of that already! The question remains,though:Why should you use this book, especially with so many other resources avail-able? The best answer is that this book is a hands-on “laboratory manual.” It is meant
to complement, not replace, other books on XML, XSLT, Java servlets and applets, andJSP Like any laboratory manual, this book assumes at least a basic understanding of thesubjects of its experiments.This book uses original material for learning its topics,within a context that invites experimentation and even controversial solutions Itavoids simple repetition of documentation that can be more easily and fully accessedelsewhere
1.3 How to Use This Book
Although you might enjoy reading this book on a long airplane ride, we hope thatyou will read it while you are trying out its code examples and while you are online.Perhaps this book is best seen as part laboratory manual and part travel guide; its use-fulness to you will depend on how much you try the examples and visit the Web linksprovided
As we know too well, today you can find on the Web a “fact” related to a subject ofthis book, only to have it become a “fiction” (or, at least, an irrelevant fact) by the timethe book is published.This is a side effect of the very popularity of our subjects; thetechnologies that we cover are evolving rapidly, and major changes are common.Thisbook will provide links for you to the most relevant Internet sources and relies onyour willingness to visit these for the latest information
The quantity of information on the Internet that is related to this book is ing rapidly Particularly active are the various mailing lists and forums, where thousands
increas-of developers worldwide are engaged in spirited debate and information interchange.Follow our advice: Subscribe to some of these mailing lists, and take part in the onlineforums.You will soon experience the fast pace at which these technologies are evolv-ing, as well as the excitement that they are generating in the worldwide community ofsoftware developers
1.3.1 How to Stay Current
You can find some links to information relevant to this book in Chapter 12.We feelthat, with evolving technology, it is vital to have sources of current information, so wewill also provide some links for you here One way to keep in touch with the entiresubject of Java programming is to subscribe to related newsgroups One important one
is comp.lang.java.programmer.You can also search all the newsgroups, including their archives, which is a greatway to generate leads to answer just about any question that comes up.To do that, justuse the search engine at http://www.dejanews.com
Trang 241.3 How to Use This Book
Another way to keep current with Java, including Java servlets, Java applets, and JSP,
is with the Sun mailing lists and archives, which you can find using these URLs:
http://archives.java.sun.com/cgi-bin/wa http://archives.java.sun.com/archives/index.html
Especially relevant to this book are discussions related to Java servlets and JSP asimplemented by the Jakarta project of the Apache Software Foundation.These can befound at http://jakarta.apache.org/getinvolved/mail.html
For staying up-to-date with XML technologies, you can join another Apache ing list by visiting http://xml.apache.org/mail.html For a more general discussion
mail-of XML and its development, try the archives mail-of the XML-L mailing list, at
http://listserv.heanet.ie/xml-l.html.Among the most useful sources of current information relevant to the subject ofthis book are the Java Technology Forums hosted by Sun Microsystems Here are someURLs that merit your attention:
http://developer.java.sun.com/developer/community/forum.jshtml http://forum.java.sun.com/list/discuss.sun.javaserver.pages http://forum.java.sun.com/list/discuss.sun.java.technology.and.xml http://forum.java.sun.com/list/discuss.sun.java.servlet.development.kit
1.3.2 Our Technology Choices in Brief
The following is a list of the technology choices that we made for developing tions based upon XML, XSLT, Java servlets and applets, and JSP:
If You Already Know These Products
You might already be familiar with these chosen products and our reasons in support of their selection If
so, you can safely skip the rest of this chapter and proceed directly to Chapter 2, “An Environment for Java Software Development.” As another alternative, some of the highlights of the following discussion are presented in italics, to allow you to quickly get the gist of the content.
It might be useful to point out that we first discuss a list of questions, without ing them Later in the chapter, we provide our own answers to those same questions
Trang 25answer-Some readers would no doubt prefer to have each question followed by our answer.
We would rather present you with an appreciation of the fact that any discipline thatcan raise many questions about how to proceed will surely have room for many cre-ative sets of answers.We do not want to leave you with the impression that ouranswers are the only ones that you should try
1.4 Some Choices Facing Web Application Developers
When you want to develop Web applications, you immediately face a series of daries For example, should you take advantage of all the relevant programming that isbuilt in only on Windows and NT computers, especially considering the popularity ofthe Microsoft Web browser? Alternatively, should you try to conform fully to the stan-dards and attempt a platform neutral solution? In the latter case, which versions of thestandards should you adopt? Which tools should you use? Which development envi-ronments and languages should you use? Should you seek a solution that is basedupon Linux, or one based on a commercial UNIX platform?
quan-1.4.1 Client-Side Versus Server-Side Processing
Web application developers who want to take advantage of Microsoft technologiesoften emphasize client-side processing.They leverage library files (DLLs) that reside onthe same machine as the Web browser Many who choose this path use Microsoftdeveloper tools, especially Visual Basic
However, there are many advantages to emphasizing the server side when ing Web applications One of these advantages is especially compelling to those of uswho have supported widely distributed software that we had to install and configure
develop-on every last client machine!
A Web application that can change, adapt, and evolve by changing only the software on a few server machines is far easier to deploy, maintain, and support than is a Web application made up
of programs that must be installed and configured on thousands of client machines.
We stated above “emphasizing the server side” because the most practical approachseems to be to allow for both server-side and client-side processing, depending uponwhat needs to be done Java developers can take advantage of Java applets, whichenable you to use client-side processing in a Web application while avoiding some ofthe software distribution problems.The Java plug-in provides a way to run Java appletstransparently on differing Web browsers According to James Gosling, the creator ofJava, the closer integration of the plug-in and browser technology is an important goalfor Java.That will help dispel criticisms of those who find the delays of downloadingthe Java plug-in and Java applets time-consuming and disruptive