ebook img

Core JSTL: mastering the JSP standard tag library PDF

603 Pages·5.384 MB·English
by  GearyDavid M
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Core JSTL: mastering the JSP standard tag library

c o r e JSTL Mastering the JSP™ Standard Tag Library DAVID M. GEARY Prentice Hall PTR, Upper Saddle River, NJ 07458 Sun Microsystems Press www.phptr.com A Prentice Hall Title © 2003 Sun Microsystems, Inc.— Printed in the United States of America. 901 San Antonio Road, Palo Alto, California 94303 U.S.A. All rights reserved. This product and related documentation are protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or related documentation may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United States Government is subject to the restrictions set forth in DFARS 252.227-7013 (c)(1)(ii) and FAR 52.227-19. The products described may be protected by one or more U.S. patents, foreign patents, or pending applications. TRADEMARKS—HotJava, Java, Java Development Kit, Solaris, SPARC, SunOS, and Sunsoft are trademarks of Sun Microsystems, Inc. All other products or services mentioned in this book are the trademarks or service marks of their respective companies or organizations. The publisher offers discounts on this book when ordered in bulk quantities. For more information, contact Corporate Sales Department, Prentice Hall PTR, One Lake Street, Upper Saddle River, NJ 07458. Phone: 800-382-3419; FAX: 201-236-7141. E-mail: [email protected]. Editorial/production supervision: Patti Guerrieri Cover design director: Jerry Votta Art director: Gail Cocker-Bogusz Series interior design: Meg Van Arsdale Manufacturing manager: Alexis R. Heydt-Long Marketing manager: Debby vanDijk Executive editor: Gregory G. Doench Associate editor: Eileen Clark Editorial assistant: Brandt Kenna Sun Microsystems Press publisher: Michael Llwyd Alread 10 9 8 7 6 5 4 3 2 1 ISBN 0-13-100153-1 Sun Microsystems Press A Prentice Hall Title This page intentionally left blank PREFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii ACKNOWLEDGMENTS . . . . . . . . . . . . . . . . . . . . . . xviii 1 INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . 2 JSTL Overview 5 What Is JSTL? 6 The JSTL Expression Language 7 The JSTL Tag Libraries 8 Getting Started 23 The JSTL Specification 23 The JSTL Reference Implementation 24 Downloading and Installing a Servlet Container 26 A Simple JSTL Web Application 30 JSTL Design Principles 34 Naming Conventions for JSTL Actions 35 Scoped Variables vs. Scripting Variables 35 vi Contents Static vs. Dynamic Action Attributes 36 Error Handling 37 Configuration Settings 37 2 THE JSTL EXPRESSION LANGUAGE . . . . . . . . . . . . .38 Expression Language Overview 40 How the Expression Language Works 40 How to Use the Expression Language 41 Expressions 41 Identifiers 43 Operators 44 Operator Precedence 45 The . and [] Operators 45 Accessing JavaBeans Components 46 Accessing Objects Stored in Arrays, Lists, and Maps 52 A Closer Look at the [] Operator 56 The empty Operator 60 Type Coercion 62 Literal Values 63 Implicit Objects 64 Accessing Request Parameters 65 Accessing Request Headers 69 Accessing Context Initialization Parameters 72 Accessing Cookies 74 Accessing Scoped Attributes 78 Accessing JSP Page and Servlet Properties 80 Method Invocation 86 EL Expressions in Custom Actions 91 Common Mistakes 95 Forgetting Curly Braces 95 Forgetting taglib Declarations 96 Neglecting to Store Variables in a Scope 96 Using Illegal Characters for Attribute Values 97 Inadvertently Using Implicit Objects 98 Contents vii 3 GENERAL-PURPOSE AND CONDITIONAL ACTIONS . . . . . . . . . . . . . . 100 General-Purpose Actions 102 The <c:out> Action 102 The <c:set> Action 111 The <c:remove> Action 125 The <c:catch> Action 126 Conditional Actions 127 Simple Conditions 128 Mutually Exclusive Conditions 132 Using Conditional and General-Purpose Actions Together 137 Conditional Custom Actions 145 4 ITERATION ACTIONS. . . . . . . . . . . . . . . . . . . . 150 The <c:forEach> Action 154 Iterating Over Integer Values 155 Iterating Over Data Structures 158 The <c:forTokens> Action 166 Iteration Status 171 Iteration Status for Integer Iterations 172 Iteration Status for Data Structure Iterations 174 Custom Iteration Actions 178 Collaboration Custom Actions 178 Iteration Custom Actions 182 5 URL ACTIONS . . . . . . . . . . . . . . . . . . . . . . . . 198 Overview 201 The <c:import> Action 201 The <c:redirect> Action 208 The <c:url> Action 208 The <c:param> Action 210 viii Contents Accessing External Resources 210 Accessing Resources in Foreign Contexts 215 Redirecting a Response 225 6 CONFIGURATION SETTINGS . . . . . . . . . . . . . . . 230 Overview 232 The FMT_LOCALE Configuration Setting 235 Temporarily Overriding Configuration Settings 235 The Config Class 239 Accessing Configuration Settings in Servlets 240 Accessing Configuration Settings in Life-Cycle Listeners 242 Accessing Configuration Settings in Custom Actions 243 7 I18N ACTIONS . . . . . . . . . . . . . . . . . . . . . . . 248 Overview 250 Localizing Messages 251 Multiple Resource Bundles 254 Compound Messages 255 I18N and L10N 258 Locales 258 Resource Bundles 259 Unicode and Charsets 260 Localization Contexts 263 An Overview of the I18N Actions 264 Use of <fmt:message> 265 Localization Context Lookup 268 Resource Bundle Lookup 274 An Example of Dynamically Switching Locales 278 Compound Messages and <fmt:param> 283 Request Encoding 287 I18N Custom Actions 293 Validation with JSP Pages 296 Validation with a Custom Action That Uses javax.servlet.jsp.jstl.fmt.LocaleSupport 304 Contents ix 8 FORMATTING ACTIONS . . . . . . . . . . . . . . . . . . 308 Formatting and Parsing Numbers 310 Custom Number Patterns 319 Percents 325 Currencies 326 Formatting and Parsing Dates and Times 333 Custom Patterns for Dates and Times 336 Using Time Zones 343 Determining a Formatting Locale 352 Formatting Locale Lookup 354 9 DATABASE ACTIONS . . . . . . . . . . . . . . . . . . . . 356 Overview 358 SQL Actions 358 Configuration Settings 359 A Simple Database 360 How JSTL Locates Data Sources 363 Creating Data Sources 365 Specify Your Data Source in the Deployment Descriptor 366 Specify Your Data Source with <sql:setDataSource> 369 Create Your Data Source in a Business Component 372 Querying a Database 378 Using <sql:query> 378 Accessing Query Properties 382 Scrolling Through Large Queries 385 Prepared Statements and SQL Parameters 389 Updating a Database 398 Database Inserts 399 Database Updates 400 Database Deletes 407 Executing Database Transactions 411 Implementing Database Custom Actions 418

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.