XML, XSLT, Java™, and JSP™
Total Page:16
File Type:pdf, Size:1020Kb
00 1089-9 FM 6/26/01 8:20 AM Page i Contents At a Glance 1 Introduction and Requirements XML, XSLT, 2 An Environment for Java Software Java, and JSP: Development 3 Java Servlets and JavaServer Pages: A Case Study in Jakarta Tomcat Developing a 4 XML and XSLT: Xerces and Xalan Web Application 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 ii 00 1089-9 FM 6/26/01 8:20 AM Page iii XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application Westy Rockwell www.newriders.com 201 West 103rd Street, Indianapolis, Indiana 46290 An Imprint of Pearson Education Boston • Indianapolis • London • Munich • New York • San Francisco 00 1089-9 FM 6/26/01 8:20 AM Page iv XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application Publisher David Dwyer Translation from the German language edition of: XML, XSLT, Java, and JSP by Westy Rockwell 2000 Galileo Press Associate Publisher GmbH Bonn, Germany Al Valvano FIRST EDITION: July 2001 Executive Editor All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or Stephanie Wall mechanical, including photocopying or recording, or by any Managing Editor information storage and retrieval system, without written Gina Brown permission from the publisher, except for the inclusion of brief quotations in a review. Product Marketing International Standard Book Number: 0-7357-1089-9 Manager Library of Congress Catalog Card Number: 00-110885 Stephanie Layton 05 04 03 02 01 7 6 5 4 3 2 1 Publicity Manager Interpretation of the printing code:The rightmost double- Susan Nixon digit number is the year of the book’s printing; the right- most single-digit number is the number of the book’s Software printing. For example, the printing code 01-1 shows that the Development first printing of the book occurred in 2001. Specialist Composed in Bembo and MCPdigital by New Riders Jay Payne Publishing Project Editor Printed in the United States of America Elise Walter Trademarks Copy Editor All terms mentioned in this book that are known to be Krista Hansing trademarks or service marks have been appropriately capital- ized. New Riders Publishing cannot attest to the accuracy of Indexer this information. Use of a term in this book should not be Larry Sweazy regarded as affecting the validity of any trademark or service Manufacturing mark. Java and JavaServer Pages (JSP) are registered trade- marks of Sun Microsystems, Inc. Coordinator Jim Conway Warning and Disclaimer Book Designer This book is designed to provide information about XML, Louisa Klucznik XSLT, Java, and JSP.Every effort has been made to make this book as complete and as accurate as possible, but no war- Cover Designer ranty or fitness is implied. Aren Howell The information is provided on an as-is basis.The authors Proofreader and New Riders Publishing shall have neither liability nor responsibility to any person or entity with respect to any loss Jeannie Smith or damages arising from the information contained in this Composition book or from the use of the discs or programs that may Gina Rexrode accompany it. 00 1089-9 FM 6/26/01 8:20 AM Page v ❖ 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:21 AM Page vi 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 vii Contents vii 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 00 1089-9 FM 6/26/01 8:21 AM Page viii viii Contents 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 00 1089-9 FM 6/26/01 8:21 AM Page ix Contents ix 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 00 1089-9 FM 6/26/01 8:21 AM Page x x Contents 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 00 1089-9 FM 6/26/01 8:21 AM Page xi Contents xi 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 00 1089-9 FM 6/26/01 8:21 AM Page 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 soft- ware developer, but his involvement with computers dates back longer yet.