Instant Download Beginning JavaServer Pages 1st Edition Vivek Chopra PDF All Chapters
Instant Download Beginning JavaServer Pages 1st Edition Vivek Chopra PDF All Chapters
com
https://ebookname.com/product/beginning-javaserver-
pages-1st-edition-vivek-chopra/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/javaserver-pages-fast-easy-web-
development-w-cd-1st-edition-aneesha-bakharia/
ebookname.com
https://ebookname.com/product/sams-teach-yourself-javaserver-pages-
in-21-days-1st-edition-steven-holzner/
ebookname.com
https://ebookname.com/product/freedom-from-addiction-the-chopra-
center-method-for-overcoming-destructive-habits-deepak-chopra/
ebookname.com
https://ebookname.com/product/dictionary-of-computing-
over-10-000-terms-clearly-defined-5th-edition-paul-roseby/
ebookname.com
https://ebookname.com/product/handbook-of-research-on-effective-
electronic-gaming-in-education-set-of-3-1st-edition-richard-e-ferdig/
ebookname.com
https://ebookname.com/product/introduction-to-pragmatics-1st-edition-
betty-j-birner/
ebookname.com
https://ebookname.com/product/diagnostic-imaging-brain-1st-edition-
anne-osborn/
ebookname.com
https://ebookname.com/product/mobile-radio-channels-2nd-edition-
matthias-patzold/
ebookname.com
Encyclopedia of Jewish American Literature Encyclopedia of
American Ethnic Literature 1st Edition Gloria L. Cronin
https://ebookname.com/product/encyclopedia-of-jewish-american-
literature-encyclopedia-of-american-ethnic-literature-1st-edition-
gloria-l-cronin/
ebookname.com
Beginning JavaServer Pages™
Vivek Chopra
Sing Li
Rupert Jones
Jon Eaves
John T. Bell
Beginning JavaServer Pages™
Beginning JavaServer Pages™
Vivek Chopra
Sing Li
Rupert Jones
Jon Eaves
John T. Bell
Beginning JavaServer Pages™
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2005 by Wiley Publishing, Inc., Indianapolis, Indiana
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 0-7645-7485-X
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
1B/QT/QS/QV/IN
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any
means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections
107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or
authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood
Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be
addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317)
572-3447, fax (317) 572-4355, e-mail: brandreview@wiley.com.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP-
RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON-
TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CRE-
ATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CON-
TAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE
UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR
OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A
COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE
AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION
OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR-
THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFOR-
MATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE.
FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE
CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services or to obtain technical support, please contact our Cus-
tomer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be
available in electronic books.
Library of Congress Cataloging-in-Publication Data
Beginning JavaServer pages / Vivek Chopra ... [et al.].
p. cm.
Includes index.
ISBN 0-7645-7485-X (paper/website)
1. JavaServer pages. 2. Web sites--Design. 3. Web site development. I. Chopra, Vivek.
TK5105.8885.J38B45 2005
006.7 6--dc22
2004024591
Trademarks: Wiley, the Wiley Publishing logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade
dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States
and other countries, and may not be used without written permission. JavaServer Pages is a trademark of Sun
Microsystems, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not
associated with any product or vendor mentioned in this book.
About the Authors
Vivek Chopra has over ten years of experience as a software developer, architect, and team lead, with
extensive experience with Web services, J2EE, and middleware technologies. He has worked and con-
sulted at a number of Silicon Valley companies and startups and has (pending) patents on Web services.
Vivek actively writes about technology and has coauthored half a dozen books on topics such as open-
source software, Java, XML, and Web services. He contributes to open source, too, and has developed
parts of the uddi4j library, an open-source Java API for UDDI.
Sing Li, first bit by the microcomputer bug in 1978, has grown up with the microprocessor age. His first
personal computer was a do-it-yourself Netronics COSMIC ELF computer with 256 bytes of memory,
mail-ordered from the back pages of Popular Electronics magazine. Currently, Sing is a consultant, system
designer, open-source software contributor, and freelance writer. He writes for several popular technical
journals and e-zines and is the creator of the Internet Global Phone, one of the very first Internet phones
available. He has authored and coauthored numerous books across diverse technical topics, including
JSP, Tomcat, servlets, XML, Jini, and JXTA.
Rupert Jones is a Technical Lead for J2EE projects at Internet Business Systems. Over the past six years,
Rupert has provided software development and consulting services for blue-chip companies, both in
Australia and internationally. He lives and works in Melbourne, Australia. Rupert can be contacted at
rup@rupertjones.com.
Jon Eaves has been developing software in a variety of languages and domains for over 15 years. He is
currently employed by ThoughtWorks, developing large-scale enterprise systems using J2EE. When he
can find spare time, he develops J2ME/MIDP applications and works on the BouncyCastle Crypto APIs
(www.bouncycastle.org). Jon can be reached at jon@eaves.org.
John T. Bell has more than 20 years of software development experience and currently serves as the lead
software architect for the Web site of a major hospitality company based in Bethesda, Maryland. He is
also an adjunct professor, teaching server-side Java technologies for the Center for Applied Information
Technology at Towson State University. He has a master’s degree in Computer Systems Management
and a bachelor’s degree in Electrical Engineering, both from the University of Maryland. This is Mr.
Bell’s third contribution to a Wrox title. He is also the author of The J2EE Open Source Toolkit.
Credits
Acquisitions Editor Project Coordinator
Robert Elliott April Farling
Sing Li
Thanks to the virtual Beginning JavaServer Pages team, top professionals from all corners of the globe.
It was wonderful working with you throughout 2003 and 2004.
To my wife, Kim—your inspiration and support are the high-octane fuel that keeps me running, looking
joyfully forward to each brave new day.
Rupert Jones
First of all, I’d like to thank my coauthors for their dedication to this book. It’s not easy holding down a
full-time job in this industry and fitting in time for such a venture. I am constantly amazed we all still
have friends and family who will talk to us, let alone recognize us. It’s been a pleasure undertaking this
task with a group of such consummate professionals.
To the Wrox crew—in particular, Sydney Jones, our developmental editor, and our tech reviewers at
DreamTech—thanks for all your hard work in getting us across the line. I know its difficult working
with technical people at the best of times, especially when they are geographically remote.
Thanks also to my colleagues at Internet Business Systems: Steve Hayes, Rob Mitchell, and Shane
Clauson. These guys provided me with much-needed help, advice, and encouragement, even in my
grumpier moments. It really is a pleasure to work with each of you.
And last but certainly not least, thanks to my loving family: Julia, Michael, Nick, and Caroline.
Jon Eaves
I’d like to thank my coauthors and the team at Wrox for the hard work they put in while creating this
book. Closer to home, I’d like to thank my family for their encouragement, patience, and support. Mum
and Dad, everything I can do is because of your love. My wonderful wife, Sue, you rock my world more
and more every day. Boo and Maddy, your purring late at night kept me going when the words
wouldn’t come. Thank you, all.
John T. Bell
To Tammy, my loving and patient wife, maybe someday I will write a book that you can read, and to my
grandmother, Valmai Locklair, who slipped away from us as I was writing my chapters.
Contents
Introduction xxv
The Right Way to Do Web Development xxv
Approach xxvi
How This Book Is Structured xxvi
Conventions xxix
Source Code xxx
Errata xxx
p2p.wrox.com xxx
x
Contents
Coercion to a character 158
Best attempt to “do the right thing” without error 158
Accessing Object Properties and Collections 162
Implicit EL Objects in JSP 2.0 167
User-Supplied Functions within EL 173
Namespace and EL functions 173
Static methods of a Java class 173
Summary 177
Exercises 178
xi
Contents
The include Directive 231
The include performed at translation time 231
Summary 239
Exercises 239
xii
Contents
Summary 328
Exercises 328
Chapter 11: Building Your Own Custom JSP Tag Library 329
What Is a Tag File? 329
A Simple Tag File: Displaying Today’s Date 330
Advantages of Tag Files 331
Code reuse 331
Hiding complexity 331
Separation of concerns 331
Simplicity 332
Flexible packaging 332
Developing Tag Files 332
Scope and implicit objects 332
Using directives in tag files 335
Body processing 341
Attributes 345
Packaging Tag Files 355
Java custom actions versus tag file custom actions 358
Summary 359
Exercises 359
xiii
Contents
Building on the Java Platform’s i18n Capabilities 399
The concept of a locale 399
Maintaining locale information 400
Summary 433
Exercises 434
xiv
Contents
Describing servlets to containers in the deployment descriptor 495
The servlet declaration 497
Using servlets when JSP is available 503
Specifying initialization parameters 504
Accessing initialization parameters within the ControllerServlet 506
Custom forwarding of incoming requests via the controller servlet 508
The forwarding targets 509
Summary 510
Exercises 510
Chapter 16: The Role of JSP in the Wider Context: Web Applications 511
What Is a Web Application? 512
Directory Structure for a Web Application 512
The Deployment Descriptor 513
Deployment descriptor elements for a JSP developer 513
Using a Web Archive 523
Development and Deployment Strategies 523
Packaging and Deploying for Tomcat 524
Introduction to Web application security 528
Summary 529
Exercises 530
xv
Contents
The Spring Framework 567
Main components of the Spring MVC 567
An example using Spring 569
Summary 589
Exercises 590
xvi
Contents
Tiles and Struts 671
Configuring Tiles with Struts 671
Tiles definitions as action forwards 671
Passing values from Struts to Tiles 673
Summary 678
Exercises 679
xvii
Contents
Using JSP with J2EE Components 729
Servlets 730
JNDI 735
JDBC 738
EJB 741
Benefits of EJB 742
Restrictions on EJB 742
Types of EJB 743
Session beans 743
Entity beans 744
Message-driven beans 745
Timer Service 745
Summary 746
Exercises 746
xviii
Contents
Authentication 837
HTTP BASIC authentication 837
Form-based authentication 843
Client-certificate authentication 849
Authorization 855
Container 855
Programmatic 855
Summary 860
Exercises 860
xix
Contents
CVS 903
Installing CVS 903
CVS concepts 903
Connecting to a CVS server 904
Checking in code 905
Checking out code 906
Comparing changes across revisions 906
Additional resources 907
JUnit 907
Installing JUnit 907
JUnit concepts 908
Additional resources 915
HttpUnit 915
Installing HttpUnit 915
HttpUnit concepts 916
Additional resources 919
Best Practices for Web Development 919
Follow good JSP coding practices 919
Separate application logic and presentation 920
Use design patterns where appropriate 920
Use frameworks for developing applications 921
Early testing and integration 921
Summary 921
Exercises 922
xx
Contents
The Development Environment 945
Directory structure 946
Build scripts 947
Struts 949
Tiles 950
Log4j 951
Rome 953
Apache Axis 956
The Application 958
View 959
Controller 966
Running the portal application 975
Summary 981
Exercises 981
xxi
Contents
xxii
Random documents with unrelated
content Scribd suggests to you:
After taking off his hat, and making a low bow,
Nibbles said:
Nibbles’ Return
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.