Beginning JSP 2: From Novice to Professional ISBN:1590593391 by Peter den Haan, Lance Lavandowska, Sathya Narayana Panduranga and Krishnaraj Perrumal Apress © 2004 (480 pages) Let this be your guide as you begin using JSP It reviews HTML and provides an overview of JSP, then demonstrates how to pull data from a database and begin using it, giving you the skills to enter the Java Development and Web Development industries Table of Contents Beginning JSP 2—From Novice to Professional Introduction Chapter 1 - Creating Your First JSP Page Chapter 2 - Learning How HTML Works Chapter 3 - Introducing JSP Chapter 4 - Working with Data Chapter 5 - Making Decisions, Decisions Chapter 6 - Reusing Code Chapter 7 - Performing Time Management Chapter 8 - Using JSP and XML Together Chapter 9 - Going Behind the Scenes Implementing the Model 2 Architecture Chapter 10 and Using Struts Appendix A - JSP Syntax Reference Appendix B - JSP Implicit Objects Appendix C - XML Configuration Files Appendix D - Getting More Information Index List of Figures List of Tables List of Trying It Outs List of Sidebars Back Cover Let Beginning JSP 2 be your guide as you begin using JSP This comprehensive guide starts by steering you through your first JSP application It reviews HTML, and provides you with a useful overview of JSP You’ll then be ready to start learning one of the core techniques in JSP: pulling data from a database and working with that data When you’ve mastered this technique, you’ll be ready to branch out powerfully into other JSP topics: variables, scope, flow control, and code reuse for productive time management Finally, the book shows you how you can use JSP with XML and gives you a taste of some advanced topics, including using Struts and the Model View Controller This book’s step-by-step examples explain the techniques behind the code The authors include realistic scenarios wherever possible to build your knowledge and confidence in JSP After reading this book, you’ll have the knowledge and skills to enter the web development and Java development industries All you need to begin this journey is a basic understanding of HTML and Java About the Authors Peter den Haan is a senior systems engineer at Objectivity Ltd., a UK-based systems integration company He began to program at the age of 13 on a Radio Shack TRS-80 model I with 16KB of memory, and he has since progressed to J2EE systems architect and lead developer for Internet and intranet projects for clients ranging from the UK Football Association Premier League to Shell Finance Lance Lavandowska has been working with JavaServer Pages since 1998 He has contributed to several Apache Jakarta projects, the Castor project, and the Roller weblogger project Lance has also served as a technical reviewer on several JSP books and is a coauthor of Professional JSP Site Design Sathya Narayana Panduranga is a software design engineer living in the software capital of India, Bangalore He has expertise in Microsoft and Java technologies, and has worked in the domains of the Internet, telecom, and convergence His favorite areas of interest are distributed and component-based application architectures, and object-oriented analysis and design Contributing to a range of technical articles and books is a hobby that gives him the immense satisfaction of being able to share his knowledge Krishnaraj Perrumal is founder and director of Adarsh Softech He has successfully developed and managed a number of software projects and e-projects, and his programming experience spans 15 years He regularly gives presentations on Java technology, XML, information systems security, and audit He is a Sun Certified Java Programmer, a Certified Novell Netware Engineer, and a Certified Information Systems Auditor Currently, he spends most of his time providing consultancy and solutions for computer security, in addition to web development IT constitutes both his profession and his hobby Beginning JSP 2—From Novice to Professional PETER DEN HAAN, LANCE LAVANDOWSKA, SATHYA NARAYANA PANDURANGA, AND KRISHNARAJ PERRUMAL EDITED BY MATTHEW MOODIE Copyright © 2004 by Peter den Haan, Lance Lavandowska, Sathya Narayana Panduranga, and Krishnaraj Perrumal All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher ISBN (pbk): 1-59059-339-1 Printed and bound in the United States of America 10987654321 Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark Lead Editor: Matthew Moodie Technical Reviewers: Scott Davis and Matthew Moodie Editorial Board: Steve Anglin, Dan Appleman, Gary Cornell, James Cox, Tony Davis, John Franklin, Chris Mills, Steve Rycroft, Dominic Shakeshaft, Julian Skinner, Jim Sumser, Karen Watterson, Gavin Wray, John Zukowski Project Manager: Sofia Marchant Copy Manager: Nicole LeClerc Copy Editor: Kim Wimpsett Production Manager: Kari Brooks Production Editor: Laura Cheu Compositor: Kinetic Publishing Services, LLC Proofreader: Liz Welch Indexer: Michael Brinkman Artist: Kinetic Publishing Services, LLC Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 175 Fifth Avenue, New York, NY 10010 and outside the United States by Springer-Verlag GmbH & Co KG, Tiergartenstr 17, 69112 Heidelberg, Germany In the United States: phone 1-800-SPRINGER, e-mail , or visit http://www.springerny.com Outside the United States: fax +49 6221 345229, e-mail orders@springer.de, or visit http://www.springer.de For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710 Phone 510-549-5930, fax 510-549-5939, e-mail , or visit http://www.apress.com The information in this book is distributed on an "as is" basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work The source code for this book is available to readers at http://www.apress.com in the Downloads section About the Authors Peter den Haan Peter den Haan is a senior systems engineer at Objectivity Ltd., a UKbased systems integration company He started out programming at 13 on a RadioShack TRS-80 model I with 16KB of memory, but he has progressed since to become a J2EE systems architect and lead developer for Internet and intranet projects for customers ranging from the UK Football Association Premier League to Shell Finance Peter has previously written the security and cryptography chapters for Beginning Java Networking He's a Sun Certified Java 2 developer, a JavaRanch bartender, a self-confessed geek; he has a doctorate degree in theoretical physics and plays bass in the local worship band You can reach him at bjsp@peterdenhaan.info Lance Lavandowska Lance Lavandowska has been working with JSP since 1998 He has contributed to several Apache Jakarta projects, the Castor project, and the Roller Weblogger project Lance has also served as a technical reviewer on several JSP books and was a coauthor on Professional JSP Site Design Sathya Narayana Panduranga Sathya Narayana Panduranga is a software design engineer living in Bangalore, the Software Capital of India He has expertise in Microsoft and Java technologies and has worked in the domains of Internet, telecom, and convergence His favorite areas of interest are distributed and component-based application architectures and object-oriented analysis and design Contributing to a range of technical articles and books is a hobby that gives him the immense satisfaction of sharing his knowledge You can contact him at Krishnaraj Perrumal Krishnaraj Perrumal is founder and director of Adarsh Softech He has successfully developed and managed a number of software projects and e-projects, and his programming experience spans the past 15 years He regularly gives presentations on Java technology, XML, information systems security, and audits He's a Sun Certified Java Programmer, a Certified Novell NetWare Engineer, and a Certified Information Systems Auditor Currently he spends most of his time providing consultancy and solutions for computer security, in addition to Web development He loves to spend all his free time with children, but being tech savvy, information technology constitutes both his profession and his hobby You can contact Krishnaraj at About the Editor Matthew Moodie Matthew Moodie enjoys a life of fun in Glasgow, Scotland He's a keen novice gardener with a houseful of plants He'd like to thank Laura for her love and friendship About the Technical Reviewer Scott Davis is a senior software engineer and instructor in the Denver, Colorado, area He has worked on a variety of Java platforms, from J2EE to J2SE to J2ME (sometimes all on the same project) He's a frequent presenter at national conferences and local user groups Most recently, he was the president of the Denver Java Users Group (http://www.denverjug.org) Introduction Welcome to Beginning JSP 2: From Novice to Professional This book is for novices and teaches JavaServer Pages (JSP) 2 using basic principles You don't need to know any Java to use this book because JSP 2 is a significant development of the JSP technology that has greatly reduced JSP's reliance on Java knowledge However, to get the most out of supporting technologies and maximize your JSP applications, you need to know some basic Java techniques We'll teach you these techniques and show you when and where to use the Java language The JSP 2 specification is the biggest revision of JSP since its creation It's now easier for nonprogrammers to build powerful, dynamic Web applications The authors of this book realize that JSP 2 is a tremendously powerful tool but that it's also a daunting prospect for many nonprogrammers In response to this, the authors have written an easily accessible guide for those who are beginning their career in Web programming This book introduces all the important concepts without fuss or overcomplication and always keeps the readers' best interests at heart Chapter 1 takes you through the Java and JSP installation processes so you're ready for the rest of the book Chapter 2 is a Hypertext Markup Language (HTML) recap, which will act as a useful reference for those who already know a little HTML After running through the basics, the book moves through simple JSP pages in Chapter 3 to working with data in Chapter 4, probably the most common and important task you'll have to undertake when using JSP After all, what's the point of using dynamic Web pages if you have no dynamic data on which to work? Chapters 5 and 6 introduce your first Java and show you how to use simple Java utility code to enhance your JSP pages The emphasis is always on JSP and how Java fits into the new JSP 2 framework Throughout these chapters you'll slowly build and incrementally improve an application that uses HTML forms, databases, and validation The book explains each stage and introduces good practice as you learn new techniques ... Welcome to Beginning JSP 2: From Novice to Professional This book is for novices and teaches JavaServer Pages (JSP) 2 using basic principles You don't need to know any Java to use this book because JSP 2 is a significant development of the JSP technology that has greatly... specifying constraints, 320 element, TLD, 419– 420 Validator facility, Struts, 305, 318 configuring Validator, 319 rules supported for Validator, 319 specifying constraints, 320 Validator Form classes, 322 ... tags, 21 6 tags, 375 tags, 371 element, TLD, 422 Index U unary operators, 148 unknown attribute element, 326 , 428 unloading, servlets, 27 6 UPDATE statements, SQL, 111