# XML - Managing Data Exchange/JSTL

The **JavaServer Pages Standard Tag Library** (Short Form: **JSTL**) is
a collection of four custom-tag libraries which extend the JSP
specification. As a component it is allocated in the Java EE Web
application development platform. The JSTL is administrated in the
setting of the Java Community Process (JCP) 052. Within the
Jakarta-Project there are reference implementations to these
specifications.

## Components

In version 1.1 the following libraries were intended:

-   core: iterative, conditional, URL-specific and general Tags
-   xml: Tags from the field XML and XML-transformation
-   sql: Tags for direct data base administration
-   i18n: Tags for formatting and internationalization

## History

In its original Version 1.0 an „Expression Language" was intended in
comparison to Version 1.1. With JSP 2.0 JSP-EL was taken up in the
JSP-specifications itself. Therefore the primary goal of JSTL 1.1 is the
adaption of the libraries to the JSP-EL for JSP 2.0. With the libraries
in version 1.2 the JSTL is up to date concerning the unification of the
Expression Language by the JSP 2.1 and JSF-1.2-specifications.
Furthermore the JSTL in Version 1.2 is part of the Java-EE-5-Platform.

## Usage of JSTL 1.1

As for the use of JSTL 1.1 the JSP-EL is required, a servlet-container
has to be conform to at least the JSP-2.0 specifications in order to be
be used on this. The reference implementation is made up of two JAR --
archives „standard.jar" and „jstl.jar". In most containers they usually
need to be located in the lib-path of the web application only. To
ensure backwards compatibility the JSTL 1.1 is referenced by the URI
„http://java.sun.com/jsp/jstl/fmt" whereas
„http://java.sun.com/jstl/fmt" is used for JSTL 1.0.

**Example JSP-page in XML-notation (JSPX):**

``` xml
<?xml version="1.0" encoding="utf-8" ?>
<jsp:root
  xmlns:jsp="http://java.sun.com/JSP/Page"
  xmlns:c="http://java.sun.com/jsp/jstl/core"
  xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
version="2.0">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <title>JSTL 1.1</title>
</head>
<body>

<h1>Iteration</h1>
<ul>
  <c:forEach var="num" begin="1" end="10">
    <li>Number<c:out value="${num}"/></li>
  </c:forEach>
</ul>

<h1>Formatting</h1>
<p>
  Currency: <fmt:formatNumber value="10000" type="currency" currencyCode="EUR" />
</p>

</body>
</html>
</jsp:root>
```

**Code-Explanations:**

In the *jsp:root* -- element the usage of the basis- und the
I18N-Taglibs (core and fmt) from the JSTL is indicated and linked to the
according XML-namespace. Under the headline *Iteration* the
*forEach-Tag* from the core-library is used: It displays the tag-body
(i.e., the content of the Tag) ten times. In this loop with *`${num}`*
you can find JSP -- Expression. With every loop cycle the current data
from *num* is displayed here. Under the headline *Formatting* the
*formatNumber*-tag from the fmt -- library of JSTL is used. Depending on
the adjusted language (this can be set by fmt:setLocale for example) the
number 10000 will be formatted (e.g. in German as „EUR 10.000,00" and in
English as „EUR 10,000.00")

## Alternatives to the JSTL

**Struts vs. JSTL:** There are in fact many instances where a Struts tag
and JSTL tag will perform equivalent functions. Unlike the
Struts-Framework the JSTL is not linked to a certain
architecture--paradigm, like the *Model--View--Controller* separation.
JSTL tags are more powerful compared to struts tags, because JSTL is a
more standard part of the J2EE specification, while at the same time
many options are available like condition checking, comparing strings,
triming white spaces, converting upper case or lower case, etc. Both
libraries own tags with identical name. So if these libraries are mixed
in applications, what is possible, it needs to be attended to use unique
prefixes(JSP) or namespaces (JSPX).

## Example Applications & Tutorials

-   Using JSTL to handle
    internationalization
-   Examples

## Weblinks

-   Suns Java JSTL Homepage
-   JSTL
    Reference
-   Jakarta Taglibs

