You are previewing Core JSTL: Mastering the JSP™ Standard Tag Library.
O'Reilly logo
Core JSTL: Mastering the JSP™ Standard Tag Library

Book Description

The breakthrough solution for easier, faster, and more powerful Web development.

  • Powerful techniques for accelerating, simplifying, and standardizing Web application development

  • In-depth coverage of JSTL 1.0, including built-in tags, the new JSTL expression language, and custom tag development

  • Written for both experienced Java platform developers and Web page authors

  • By the best-selling author of Graphic Java and Advanced JavaServer Pages

Using JSTL, software developers and Web page authors can create robust, flexible Web applications more quickly and easily than ever before. Now, best-selling author and JSTL expert David Geary presents the definitive guide to JSTL: its built-in tags, powerful expression language, and extensibility. Through practical examples and extensive sample code, Geary demonstrates how JSTL simplifies, streamlines, and standardizes a wide range of common Web development tasks and helps you build Web applications far more easily than JavaServer Pages technology alone.

Key topics covered:

  • Building HTML forms; accessing form data, JavaBeans components (beans), collections, and maps; constructing URLs and importing their content; redirecting HTTP responses; iterating over collections of objects; handling errors

  • Localizing Web sites for multiple languages and countries, including localizing text and formatting and parsing numbers, currencies, percents, and dates.

  • Creating and accessing data sources, making queries and iterating over the results; performing database inserts, updates, and deletes; executing database transactions

  • Parsing XML documents; using XPath with JSTL custom actions; transforming XML with XSLT, filtering XML; accessing external entities

Core JSTL shows you how to:

  • Use JSTL to simplify Web development tasks

  • Use the new JSTL expression language

  • Access databases and execute transactions

  • Develop internationalized Web sites

  • Work with XML documents and JSP technology

  • Extend JSTL with custom tags

Table of Contents

  1. Copyright
  2. About Prentice Hall Professional Technical Reference
  3. Preface
    1. 1.1. What This Book Is About
    2. 1.2. The Servlet and JSP APIs This Book Depends Upon
    3. 1.3. The Book's Web Site
    4. 1.4. How This Book's Code Was Tested
    5. 1.5. This Book's Audience
    6. 1.6. How To Use This Book
    7. 1.7. Conventions Used in This Book
  4. Acknowledgments
  5. 1. Introduction
    1. 1.1. JSTL Overview
      1. What Is JSTL?
      2. The JSTL Expression Language
      3. The JSTL Tag Libraries
        1. Twin Libraries
        2. Core Actions
        3. Formatting Actions
        4. SQL Actions
        5. XML Actions
        6. The JSTL Tag Library Validators
    2. 1.2. Getting Started
      1. The JSTL Specification
      2. The JSTL Reference Implementation
      3. Downloading and Installing a Servlet Container
        1. Tomcat
        2. Resin
    3. 1.3. A Simple JSTL Web Application
    4. 1.4. JSTL Design Principles
      1. Naming Conventions for JSTL Actions
      2. Scoped Variables vs. Scripting Variables
        1. The var and scope Attributes
        2. Scoped Variable Visibility
      3. Static vs. Dynamic Action Attributes
      4. Error Handling
      5. Configuration Settings
  6. 2. The JSTL Expression Language
    1. 2.1. Expression Language Overview
      1. How the Expression Language Works
      2. How to Use the Expression Language
    2. 2.2. Expressions
    3. 2.3. Identifiers
    4. 2.4. Operators
      1. Operator Precedence
      2. The . and [] Operators
      3. Accessing JavaBeans Components
      4. Accessing Objects Stored in Arrays, Lists, and Maps
      5. A Closer Look at the [] Operator
        1. The [] Operator's Special Ability
      6. The empty Operator
    5. 2.5. Type Coercion
    6. 2.6. Literal Values
    7. 2.7. Implicit Objects
      1. Accessing Request Parameters
      2. Accessing Request Headers
      3. Accessing Context Initialization Parameters
      4. Accessing Cookies
      5. Accessing Scoped Attributes
      6. Accessing JSP Page and Servlet Properties
    8. 2.8. Method Invocation
    9. 2.9. EL Expressions in Custom Actions
    10. 2.10. Common Mistakes
      1. Forgetting Curly Braces
      2. Forgetting taglib Declarations
      3. Neglecting to Store Variables in a Scope
      4. Using Illegal Characters for Attribute Values
      5. Inadvertently Using Implicit Objects
  7. 3. General-Purpose and Conditional Actions
    1. 3.1. General-Purpose Actions
      1. The <c:out> Action
        1. Setting Attributes for HTML Elements
        2. Retaining Values for HTML Text Elements
        3. Accessing Bean Properties
      2. The <c:set> Action
        1. Setting Bean Properties and Map Entries
          1. Setting Bean Properties
          2. Setting Compound Bean Properties
          3. Adding, Removing, and Modifying Map Entries
      3. The <c:remove> Action
      4. The <c:catch> Action
    2. 3.2. Conditional Actions
      1. Simple Conditions
        1. Retaining Values for HTML Option Elements
      2. Mutually Exclusive Conditions
        1. Implementing If/Else Constructs
        2. Implementing Switch Statement Constructs
    3. 3.3. Using Conditional and General-Purpose Actions Together
    4. 3.4. Conditional Custom Actions
  8. 4. Iteration Actions
    1. 4.1. The <c:forEach> Action
      1. Iterating Over Integer Values
      2. Iterating Over Data Structures
        1. Using the begin, end, and step Attributes for Data Structures
    2. 4.2. The <c:forTokens> Action
    3. 4.3. Iteration Status
      1. Iteration Status for Integer Iterations
      2. Iteration Status for Data Structure Iterations
    4. 4.4. Custom Iteration Actions
      1. Collaboration Custom Actions
      2. Iteration Custom Actions
        1. Custom Actions That Iterate Over Integer Values
        2. Custom Actions That Iterate Over Data Structures
  9. 5. URL Actions
    1. 5.1. Overview
    2. 5.2. The <c:import> Action
    3. 5.3. The <c:redirect> Action
    4. 5.4. The <c:url> Action
    5. 5.5. The <c:param> Action
    6. 5.6. Accessing External Resources
    7. 5.7. Accessing Resources in Foreign Contexts
    8. 5.8. Redirecting a Response
  10. 6. Configuration Settings
    1. 6.1. Overview
      1. The FMT_LOCALE Configuration Setting
      2. Temporarily Overriding Configuration Settings
    2. 6.2. The Config Class
      1. Accessing Configuration Settings in Servlets
      2. Accessing Configuration Settings in Life-Cycle Listeners
      3. Accessing Configuration Settings in Custom Actions
  11. 7. I18N Actions
    1. 7.1. Overview
      1. Localizing Messages
      2. Multiple Resource Bundles
      3. Compound Messages
    2. 7.2. I18N and L10N
      1. Locales
      2. Resource Bundles
        1. Resource Bundles as Properties Files
        2. Resource Bundles as Java Classes
      3. Unicode and Charsets
    3. 7.3. Localization Contexts
    4. 7.4. An Overview of the I18N Actions
    5. 7.5. Use of <fmt:message>
      1. Localization Context Lookup
        1. 1. If the <fmt:message> bundle attribute is specified, use it.
        2. 2. If the <fmt:message> action is nested in a <fmt:bundle>, use the enclosing <fmt:bundle> action's localization context.
        3. 3. Use the FMT_LOCALIZATION_CONTEXT configuration setting.
      2. Resource Bundle Lookup
        1. Locales
        2. The Resource Bundle Lookup Algorithm
      3. An Example of Dynamically Switching Locales
      4. Compound Messages and <fmt:param>
    6. 7.6. Request Encoding
    7. 7.7. I18NCustom Actions
      1. Validation with JSP Pages
      2. Validation with a Custom Action That Uses javax.servlet.jsp.jstl.fmt.LocaleSupport
  12. 8. Formatting Actions
    1. 8.1. Formatting and Parsing Numbers
      1. Custom Number Patterns
      2. Percents
      3. Currencies
    2. 8.2. Formatting and Parsing Dates and Times
      1. Custom Patterns for Dates and Times
    3. 8.3. Using Time Zones
    4. 8.4. Determining a Formatting Locale
      1. 1. An Enclosing <fmt:bundle> Action
      2. 2. The FMT_LOCALIZATION_CONTEXT Configuration Setting
      3. 3. Formatting Locale Lookup
      4. Formatting Locale Lookup
  13. 9. Database Actions
    1. 9.1. Overview
      1. SQL Actions
      2. Configuration Settings
    2. 9.2. A Simple Database
    3. 9.3. How JSTL Locates Data Sources
    4. 9.4. Creating Data Sources
      1. Specify Your Data Source in the Deployment Descriptor
      2. Specify Your Data Source with <sql:setDataSource>
      3. Create Your Data Source in a Business Component
        1. A Simple Data Source
        2. Creating a Data Source in an Initialization Servlet
    5. 9.5. Querying a Database
      1. Using <sql:query>
      2. Accessing Query Properties
      3. Scrolling Through Large Queries
      4. Prepared Statements and SQL Parameters
        1. Date Parameters
    6. 9.6. Updating a Database
      1. Database Inserts
      2. Database Updates
      3. Database Deletes
    7. 9.7. Executing Database Transactions
    8. 9.8. Implementing Database Custom Actions
  14. 10. XML Actions
    1. 10.1. A Simple XML File
    2. 10.2. XML Actions Overview
    3. 10.3. XPath Overview
      1. XPath Expressions and Types
      2. XPath Type Coercion
      3. XPath Functions
    4. 10.4. Parsing XML
    5. 10.5. Using Scoped Variables in XPath Expressions
    6. 10.6. Transforming XML with XSLT
      1. Using Transformation Parameters
    7. 10.7. Filtering XML
    8. 10.8. Accessing External Entities
  15. 11. JSTL Reference
    1. 11.1. Action Reference Index
      1. Core Actions
      2. Formatting Actions
      3. SQL Actions
      4. XML Actions
      5. Exposed Classes and Interfaces Index
        1. Core Classes and Interfaces
        2. Formatting Classes and Interfaces
        3. SQL Classes and Interfaces
    2. 11.2. General-Purpose Actions
    3. 11.3. Conditional Actions
      1. JSTL Conditional Actions
      2. Exposed Class
    4. 11.4. Iteration Actions
      1. JSTL Iteration Actions
      2. Exposed Classes and Interfaces
    5. 11.5. URL Actions
    6. 11.6. Internationalization Actions
      1. Overview of JSTL Internationalization Actions
      2. JSTL Internationalization Configuration Settings
        1. FMT_LOCALE
        2. FMT_FALLBACK_LOCALE
        3. FMT_LOCALIZATION_CONTEXT
      3. JSTL Internationalization Actions
      4. Exposed Classes
    7. 11.7. Formatting Actions
      1. Overview of the JSTL Formatting Actions
      2. JSTL Formatting Configuration Settings
      3. JSTL Formatting Actions
    8. 11.8. Database Actions
      1. Overview of JSTL SQL Actions
      2. JSTL SQL Configuration Settings
      3. JSTL SQL Actions
      4. Exposed Classes and Interface
    9. 11.9. XML Core Actions
    10. 11.10. XML Flow Control Actions
    11. 11.11. XML Transform Actions
  16. Setting Up the MySQL Database Used in This Book
    1. A.1. Download and Install MySQL
    2. A.2. Download and Install a JDBC Driver for MySQL
    3. A.3. Create a MySQL Database for Core JSTL Examples
    4. A.4. Populate the MySQL Database Used in Core JSTL Examples