Skip Headers
Oracle® Containers for J2EE JSP Tag Libraries and Utilities Reference
10g Release 3 (10.1.3)
Part No. B14425-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

2 Support for the JavaServer Pages Standard Tag Library

The JavaServer Pages Standard Tag Library (JSTL) provides an extensive set of tags that encapsulate much of the functionality most often included in JSP pages. JSTL was created with the stated goal of helping to simplify the lives of page authors, and goes a long way towards doing so by helping to eliminate the need for Java scripting elements in JSP pages.

For complete information about JSTL 1.1, refer to the Sun Microsystems specification at the following location:

http://java.sun.com/products/jsp/jstl/


Note:

The JSTL distribution is no longer installed in the ORACLE_HOME/j2ee/home/jsp/lib/taglib directory within OC4J. These libraries are now installed in ORACLE_HOME/j2ee/home/default-web-app\/WEB-INF/lib.

Key features of JSTL 1.1 include the following:

Note that JSTL 1.1 was released primarily to align the JSTL with the current JSP 2.0 specification. A key feature is the replacement of the parallel libraries provided with JSTL 1.0 - one that accepted expression language (EL) expressions and another that accepted standard Java expressions - with a single set of libraries that can be used with either type of expression. A new library containing convenient expression language (EL) functions that can be used within EL expressions has also been added.


Note:

Although the expression language (EL) was originally introduced with JSTL 1.0, it is now part of the JSP 2.0 specification. However, JSTL 1.1 and the EL continue to complement one another extensively to further simplify the code required to access and manipulate application data. See the Support for JavaServer Pages Developer's Guide for information on the EL.

2.1 Overview of the JSTL

The following sections provide an overview of JSTL features and OC4J support:

2.1.1 Philosophy of the JSTL

The JSTL is intended as a convenience for JSP page authors who are not familiar or not comfortable with scripting languages such as Java. Historically, scriptlets have been used in JSP pages to process dynamic data. With JSTL, the intent is for JSTL tag usage to replace the need for scriptlets.

Readers who have used previous versions of the OC4J JSP product will recognize this as similar to the goals of the Oracle JavaServer Pages Markup Language (JML) tag library, which has been officially removed and is no longer supported as of Oracle Application Server 10g Release 3 (10.1.3).

2.1.2 Summary of the JSTL Tags

The JSTL is actually comprised of five libraries, each implementing specific areas of functionality. Table 2-1 shows the standard TLD URI and prefix for each library.

Table 2-1 JSTL Libraries

Library URI Prefix

Core

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

c:

XML processing

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

x:

SQL database access

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

sql:

I18N internationalization and formatting

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

fmt:

EL functions

http://java.sun.com/jsp/jstl/functions

fn:


Table 2-2 summarizes the JSTL tags, organized into functional groups. The JSTL standard tag prefix is noted for each group.

Table 2-2 Summary of JavaServer Pages Standard Tag Library

Tag Group Description of Group Individual Tags

Core, EL support

Includes tags to evaluate an expression and output the result to the current JspWriter object, set the value of a scoped variable or of a property of a target object, remove a scoped variable, and catch a Throwable instance thrown by a nested action.

c:out c:set c:remove c:catch

Core, conditional

Includes tags to evaluate body content if a test attribute evaluates as true, and specify mutually exclusive conditional execution paths. The when and otherwise tags are used with the choose tag.

c:if c:choose c:when c:otherwise

Core, iterators

Includes tags to iterate body execution over a collection of objects, or a specified number of times, and iterate over a set of tokens separated by supplied delimiters.

c:forEach c:forTokens

Core, URL-related

Includes tags to import the content of a URL-based resource, create a URL using appropriate rewriting rules, send an HTTP redirect to the client, and add a request parameter to a URL. The param tag is a subtag of the import, url, and redirect tags.

c:import c:url c:redirect c:param

XML, core

Includes tags to parse an XML document, evaluate an XPath expression and output the result to the current JspWriter object, and evaluate an XPath expression and store the result in a scoped variable. (See the note after this table regarding XPath.)

x:parse x:out x:set

XML, flow control

Includes tags to evaluate a specified XPath expression and render its content if the expression evaluates as true, specify mutually exclusive conditional execution paths, and evaluate a specified XPath expression and repeat body execution over the result. The when and otherwise tags are used with the choose tag.

x:if x:choose x:when x:otherwise x:forEach

XML, transforms

Includes tags to apply an XSLT style sheet transformation to a document, and set transformation parameters. The param tag is a subtag of the transform tag.

x:transform x:param

SQL

Includes tags to query a database, update a database (UPDATE/INSERT/DELETE), establish a transaction context for queries and updates, export a data source as a scoped variable or data source configuration variable, set the values for parameter placeholders ("?") in a SQL statement, and set the values for parameter placeholders where the type is java.util.Date. The param and dateParam tags are subtags of the query and update tags.

sql:query sql:update sql:transaction sql:setDataSource sql:driver sql:param sql:dateParam

I18N, internationalization

Includes tags to store a specified locale in the locale configuration variable, create an I18N localization context for use within the tag, create a localization context and store it for use outside the tag, look up a localized message in a resource bundle, and set the request character encoding. The param tag can be used with the message tag to replace a parameter in the message tag.

fmt:locale fmt:bundle fmt:message fmt:param fmt:requestEncoding

I18N, formatting

Includes tags to specify a time zone for formatting or parsing, store a specified time zone in a scoped variable or time zone configuration variable, format a numeric value as appropriate for a locale or special customization, parse the string representation of a numeric value that had been formatted for a locale or special customization, format a date or time for a locale or special customization, and parse the string representation of a date or time that had been formatted for a locale or special customization.

fmt:timeZone fmt:setTimeZone fmt:formatNumber fmt:parseNumber fmt:formatDate fmt:parseDate

EL functions, collection or string length

Includes a single tag that returns the number of objects in a Collection or the number of characters in a String. The tag must be used within an EL expression.

fn:length

EL functions, string manipulation

Includes tags for changing string capitalization, getting a subset of a string, replacing characters in a string, checking if a string contains another string, escaping XML characters, and trimming a string. Tags must be used within an EL expression.

fn:contains fn:containsIgnoreCase fn:endsWith fn:escapeXML fn:indexOf fn:join fn:replace fn:split fn:startsWith fn:substring fn:substringAfter fn:substringBefore fn:toLowerCase fn:toUpperCase fn:trim



Note:

JSTL tags for XML processing are based on XPath (XML Path), a W3C recommendation. XPath provides a concise notation for specifying and selecting parts of an XML document. Refer to the following Web site for information:
http://www.w3.org/TR/xpath

2.1.3 Overview of Additional JSTL Features

The following discussions cover additional JSTL features:

2.1.3.1 Scoped Variables

JSTL tags make data available through JSP scoped attributes, referred to as scoped variables, which are used in place of scripting variables. JSTL tags that can make data available in this way have var and scope among their attributes, used as follows:

  • var: the variable that is to be exposed

  • scope: the scope of the variable, either page (default), request, session, or application

The scope attribute would not be relevant for NESTED variables (which would always have page scope), but variables in the JSTL are AT_END (available from the end-tag to the end of the page).

The following example uses the core library iterator action tag forEach and expression language support tag out to expose the current item of an employees collection:

<c:forEach var="employee" items="${customers}">
   The current employee is <c:out value="${customer}"/>
</c:forEach>

2.1.3.2 Configuration Data and the Config Class

JSTL includes functionality to dynamically override JSP configuration data for a particular scope, through a scoped variable. You can accomplish this using functionality of the javax.servlet.jsp.jstl.core.Config class.

According to the JSP specification, all scopes (page, request, session, and application) that exist within a JSP page context should together form a single namespace; that is, the name of a scoped variable should be unique across execution of a page.

The Config class has functionality to transparently manipulate configuration parameter names to produce the effect that each scope has its own namespace. Effectively, this enables you to set a configuration parameter for a particular scope only.

See the JSTL 1.1 specification for complete information.

2.1.4 JSTL Usage Notes and Future Considerations

Be aware off the following considerations:

  • The custom XML and data-access (SQL) tag libraries provided with OC4J pre-date JSTL and have areas of duplicate functionality. For standards compliance, it is now generally advisable to use JSTL instead of the custom libraries. For features in the custom libraries that are not yet available in JSTL, where there seems to be general usefulness, Oracle will try to have the features adopted into the JSTL standard as appropriate.