You are previewing JSTL: JSP Standard Tag Library Kick Start.
O'Reilly logo
JSTL: JSP Standard Tag Library Kick Start

Book Description

The JSP Standard Tag Library is a collection of commonly used functions and tools invaluable to JSP developers to avoid re-creating the same functions on site after site. Sun has indicated that JSP development should be based around using tag libraries going forward, and will relase JSP STL, as their official library. This book starts with an in-depth deiscussion of the JSP STL, then goes beyond the standard library to teach developers to create their own tags to further encapsulate the most common features of their specific applications. Along the way, readers will also learn to use tags to access data, process XML, handle expressions, and further customize pages for international visitors. Later chapters explain how readers can expand the Standard Tab Library by creating their own tags.

Table of Contents

  1. Copyright
    1. Dedication
  2. About the Author
  3. Acknowledgments
  4. Tell Us What You Think!
  5. Introduction
    1. The Benefits of JSTL
    2. JSTL and JSP
    3. Who This Book Is For
    4. Structure and Organization of the Book
    5. The Forum Application
    6. Source Code and Updates
  6. 1. Understanding JSP Custom Tags
    1. The Role of Tags in JSP
      1. Using HTML
      2. Using JSP Scriptlets
      3. Programming in Tags
    2. Introducing JSTL
      1. The Apache Taglibs Project
      2. The Structure of JSTL
        1. The Core Tag Library
        2. The XML Tag Library
        3. The I18N Tag Library
        4. The Relational DBTags (SQL) Library
    3. Installing JSTL
      1. Adding JSTL to Your Web Server
      2. Using JSTL in Your JSP Pages
      3. Testing the Counting Example
      4. Troubleshooting the Counting Example
      5. Summary
  7. 2. Programming the JSP Standard Tag Library
    1. Understanding Scoped Variables
      1. Page Scope
      2. Request Scope
      3. Session Scope
      4. Application Scope
    2. Accessing Application Data
      1. Accessing Page Context Data
      2. The paramValues Collection
    3. The Basics of Web Application Programming
      1. Processing the Query String
      2. Working with Forms
      3. Understanding State
    4. Summary
  8. 3. Understanding Basic Tag Logic
    1. Exception Processing
      1. Generating Exceptions
      2. Using the <c:catch> Tag
    2. Using Conditionals
      1. Using the <c:if> Tag
      2. Using the <c:choose> Tag
      3. Using the <c:when> Tag
      4. Using the <c:otherwise> Tag
      5. Nesting Conditionals
    3. A Chat Application
    4. Summary
  9. 4. Using the Expression Language
    1. JSTL Expression Tags
      1. Using the <c:out> Tag
      2. Using the <c:set> Tag
      3. Using the <c:remove> Tag
    2. Using the EL Expression Language
      1. Accessing Properties
      2. Literals
      3. Property Access Operators: [] and.
      4. Arithmetic Operators
        1. Addition, Subtraction, and Multiplication
        2. Division
        3. The Modulo Operator
        4. The Unary Minus Operator
      5. Relational Operators
        1. Equality and Inequality Operators
      6. Logical Operators
        1. The and and or Operators
        2. The Unary Not Operator
      7. Operator Precedence
      8. Reserved Words
      9. Implicit Objects
      10. Type Conversion
        1. Coerce to a String
        2. Coerce to a Primitive Numeric Type
        3. Coerce to a Character
        4. Coerce to a Boolean
    3. Using the RT Expression Language
      1. Determining the Browser
      2. Case-Insensitive String Comparisons
    4. Summary
  10. 5. Collections, Loops, and Iterators
    1. Understanding Collections
    2. The Iteration Tags
      1. The <c:forEach> Tag
      2. Loop Status
        1. The getCurrent() Method
        2. The getIndex() Method
        3. The getCount() Method
        4. The isFirst() Method
        5. The isLast() Method
        6. The getBegin() Method
        7. The getEnd() Method
        8. The getStep() Method
    3. Using Iterators
      1. Iterating over Strings
      2. Fixed-Length Loops
      3. The <c:forTokens> Tag
      4. Modifying a Collection
      5. Tag Collaboration with a Fixed Loop
      6. Tag Collaboration with a Collection
    4. Summary
  11. 6. Formatting Data with Tags
    1. Formatting
      1. Using the <fmt:formatNumber> Tag
      2. Formatting Percents
      3. Using the <fmt:formatDate> Tag
    2. Parsing
      1. Using the <fmt:parseNumber> Tag
      2. Using the <fmt:parseDate> Tag
    3. Time Zones
      1. Setting Time Zones
        1. Using the <fmt:timeZone> Tag
        2. Specifying the Time Zone in web.xml
        3. Using the <fmt:setTimeZone> Tag
      2. Using Time Zones
    4. Applying Date Formatting
    5. Summary
  12. 7. Accessing Data with SQL Tags
    1. Introducing the Forum Example
      1. Database Layout
        1. Setting Up the Forum on SQL Databases
        2. Setting Up the Forum on Microsoft Access
        3. Database Tables
      2. Screen Layout
    2. Understanding JDBC Drivers
      1. Connecting to a JDBC Data Source
        1. Transparent Collaboration
        2. Explicit Collaboration via Application Logic
        3. Explicit Collaboration via the <sql:setDataSource> Tag
      2. Using the <sql:setDataSource> Tag
        1. Connecting to MySQL
        2. Connecting to Microsoft Access
      3. Connecting to Other Databases
    3. Using SQL Tags
      1. Using the <sql:query> Tag
      2. Using the <sql:update> Tag
      3. Using the <sql:transaction> Tag
      4. Using the <sql:param> Tag
      5. Using the <sql:dateParam> Tag
    4. Implementing the Forum Example
      1. Using a Query to Log In
        1. Preparing the Login Form
        2. Handling a POST
      2. Using an Update to Register
      3. Welcome to the Forum
      4. Using Transactions to Administer the Forum
    5. A General Query Engine
    6. Summary
  13. 8. Accessing Data with XML Tags
    1. Understanding XML
    2. Understanding XPath
    3. Understanding XML Core Tags
      1. Using the <x:parse> Tag
      2. Using the <x:out> Tag
      3. Using the <x:set> Tag
    4. Using XML Flow-Control Tags
      1. Using the <x:forEach> Tag
      2. Using the <x:if> Tag
      3. Using the <x:choose> Tag
      4. Using the <x:when> Tag
      5. Using the <x:otherwise> Tag
    5. Transforming XML with XSLT
      1. Using the <x:transform> Tag
      2. Using the <x:param> Tag
    6. Summary
  14. 9. Accessing Internet Resources with JSTL
    1. The URL-Related Tags
      1. Using the <c:import> Tag
        1. Character Encoding
        2. Handling Relative and Absolute URLs
          1. Relative URL—Same Context
          2. Relative URL—Foreign Context
          3. Absolute URLs
      2. Using the <c:url> Tag
      3. Using the <c:param> Tag
      4. Using the <c:redirect> Tag
    2. Understanding Internet Resources
      1. Introducing RSS
      2. Using the RSS Format
    3. Summary
  15. 10. Understanding JSTL Internationalization
    1. The I18N-Related Tags
      1. Using the <fmt:setLocale> Tag
      2. Using the <fmt:setBundle> Tag
      3. Using the <fmt:bundle> Tag
      4. Using the <fmt:message> Tag
      5. Using the <fmt:param> Tag
      6. Using the <fmt:requestEncoding> Tag
    2. Resource Bundles
      1. What Is a Resource Bundle?
      2. Creating a Properties File Resource Bundle
      3. Creating a Resource Bundle for a Romance Language
      4. Creating a Resource Bundle for a Non-Romance Language
      5. Compiling the Resource Bundles
    3. A Multilingual Forum Application
    4. Summary
  16. 11. Creating Your Own Tag Libraries
    1. Developing Custom Tag Libraries
      1. Tags Used by the Forum Application
      2. Data Structures Used by the Forum Application
        1. Storing Users
        2. Storing Forums
        3. Storing Messages
    2. The Components of a Tag Library
      1. The Tag Library Descriptor File (TLD)
        1. The TLD File Header
        2. Tag Definitions
      2. Updating web.xml for Custom Tags
        1. Including Tag Libraries in web.xml
        2. Storing Configuration Information in web.xml
      3. Creating the Tag Classes
        1. Handling Sessions
        2. Obtaining a New Session
        3. Handling Scope
        4. Retrieving a Single Record
        5. Retrieving a Collection
        6. Encapsulating Functionality
      4. Constructing the Tags
        1. Retrieving a Single Record
          1. Accessing Attributes
          2. Evaluating EL Expressions
          3. The doEndTag() Method
        2. Retrieving a Collection
        3. Encapsulating Functionality
        4. Tags with Bodies
      5. Creating the JAR File
      6. Using the Tags from JSP
    3. Summary
  17. 12. Debugging and Deploying Tag Libraries
    1. Debugging
      1. General Exceptions
      2. A JSTL-Specific Error
      3. An Error in a Tag Library
    2. Debugging with an IDE
      1. Introducing Eclipse
      2. Using Eclipse with Tomcat
      3. Creating Your Own Project
      4. Debugging the Forum Application
    3. Deploying Web Applications
      1. Understanding WAR Files
      2. Distributing a WAR File
    4. Summary
  18. A. JSTL Reference
    1. The Core Tags
      1. The <c:catch> Tag
      2. The <c:choose> Tag
      3. The <c:forEach> Tag
      4. The <c:forTokens> Tag
      5. The <c:if> Tag
      6. The <c:import> Tag
      7. The <c:otherwise> Tag
      8. The <c:out> Tag
      9. The <c:param> Tag
      10. The <c:redirect> Tag
      11. The <c:remove> Tag
      12. The <c:set> Tag
      13. The <c:url> Tag
      14. The <c:when> Tag
    2. The I18N Tags
      1. The <fmt:bundle> Tag
      2. The <fmt:formatDate> Tag
      3. The <fmt:formatNumber> Tag
      4. The <fmt:message> Tag
      5. The <fmt:param> Tag
      6. The <fmt:parseDate> Tag
      7. The <fmt:parseNumber> Tag
      8. The <fmt:requestEncoding> Tag
      9. The <fmt:setBundle> Tag
      10. The <fmt:setLocale> Tag
      11. The <fmt:setTimeZone> Tag
      12. The <fmt:timeZone> Tag
    3. The Relational Database Tags (SQL)
      1. The <sql:dateParam> Tag
      2. The <sql:param> Tag
      3. The <sql:query> Tag
      4. The <sql:setDataSource> Tag
      5. The <sql:transaction> Tag
      6. The <sql:update> Tag
    4. The XML Tags
      1. The <x:choose> Tag
      2. The <x:forEach> Tag
      3. The <x:if> select Tag
      4. The <x:otherwise> Tag
      5. The <x:out> Tag
      6. The <x:param> Tag
      7. The <x:parse> Tag
      8. The <x:set> Tag
      9. The <x:transform> Tag
      10. The <x:when> Tag
  19. B. Installing JSTL and Tomcat
    1. Installing JDK
    2. Installing Tomcat
    3. Installing the Book Examples
    4. The Classpath and Search Path
    5. Installing JSTL without the Examples
  20. C. Installing MySQL
    1. Obtaining and Installing MySQL
    2. Setting Up MySQL
    3. Creating the Forum Example
    4. Installing a JDBC Driver
  21. D. Unix Installation Notes