Introducing JSTL

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

JSTL: JSP Standard Tag Library Kick Start
By Jeff Heaton

Table of Contents
Chapter 1.  Understanding JSP Custom Tags


We now examine the actual structure of JSTL and how to use it. We begin by examining the Apache Taglibs project, which includes the reference implementation of JSTL. Then, we examine the components of JSTL itself.

The Apache Taglibs Project

The implementation of JSTL that we use in this book is a part of the Apache Software Foundation's Jakarta Taglibs project. The Taglibs project includes many tag libraries other than JSTL. All of these tag libraries can be used in JSP pages. You can find more information about the Taglibs project at http://jakarta.apache.org/taglibs/. You can use the tag libraries provided by the Taglibs project to add functionality to your JSP pages. However, keep in mind that some of the tag libraries available in the Taglibs project add features that are not currently supported by JSTL.

The Structure of JSTL

JSTL itself is made up of four smaller tag libraries. These tag libraries allow you to choose which components of JSTL you will use in your program. Table 1.1 summarizes the four components of JSTL.

Table 1.1. The Four Components of JSTL

Component

URI

Prefix

Core

http://java.sun.com/jstl/core

c

XML Processing

http://java.sun.com/jstl/xml

x

I18N Formatting

http://java.sun.com/jstl/fmt

fmt

Relational DB Access (SQL)

http://java.sun.com/jstl/sql

sql

Because JSTL includes two expression languages, there are actually eight tag libraries available. To support both the new EL expression language as well as the older scriptlet-based expression language (RT), Sun introduced the concept of "twin tag libraries." To use the scriptlet-based expression language, you must place the suffix-rt on each of the previously mentioned tag libraries. We cover this topic in greater detail in Chapter 4.

The Core Tag Library

The Core tag library contains most of the important tags that you would use for any sort of application. These include the flow control statements, such as if and else. Looping and iteration are also provided by the Core tag library.

We discuss the Core tag library through much of this book. Chapters 2, 3, 5, and 6 specifically cover this library. To use the Core tag library from a JSP page, you must include the following line near the top of your JSP page:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> 
The XML Tag Library

The XML tag library provides tags that you can use to access XML documents. Using this tag library ensures that your JSP pages can easily integrate with XML.

Chapter 8, "Accessing Data with XML Tags," specifically addresses the XML tag library. To use the XML tag library from a JSP page, you have to include the following line near the top of your JSP page:

<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %> 
The I18N Tag Library

The I18N (a common abbreviation for internationalization) tag library provides many tags that help with the proper formatting of data from international applications. The I18N tag library allows resource bundles to be used in place of language-specific strings. A resource bundle is a collection of language-specific strings that the application can swap with the resource bundle for another language.

We examine the I18N tag library in Chapter 10, "Understanding JSTL Internationalization." To use the I18N tag library from a JSP page, you must include this line near the top of your JSP page:

<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %> 
The Relational DBTags (SQL) Library

Generally, it is not considered good programming practice to directly access a database from JSP pages. This is because it is often better to keep something that is as system-dependent as database access out of the presentation layer of the Web application. Therefore, database access is almost always relegated to backend components, such as Enterprise JavaBeans (EJB).

Yet you might still have reason to access SQL directly from a JSP page: for example, for the purpose of debugging or prototyping. JSTL provides a rich set of tags that you can use to access and manipulate any SQL-compatible database.

If you want information about the database tag library, see Chapter 7, "Accessing Data with SQL Tags." To use this library from a JSP page, be sure to include the following line near the top of your JSP page:

<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %> 

    printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
    Top

    [0672324504/ch01lev1sec2]

     
     


    JSTL. JSP Standard Tag Library Kick Start
    JSTL: JSP Standard Tag Library Kick Start
    ISBN: 0672324504
    EAN: 2147483647
    Year: 2001
    Pages: 93
    Authors: Jeff Heaton

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net