JavaServer Pages Standard Tag Library

from Wikipedia, the free encyclopedia
JSTL
Developer: Eclipse Foundation
Current  version : 1.2.1   (December 2011)
Operating system : platform independent
License : Eclipse Public License 2.0, GPL linking exception
https://jstl.java.net

The JavaServer Pages Standard Tag Library (abbr .: JSTL ) is a collection of four custom tag libraries that are useful for creating JSP pages.

The JSTL is managed as part of the Java Community Process (JCP) under JSR 052. There are reference implementations for this specification within the Jakarta project .

Components

The following libraries are provided in version 1.1:

history

In the original version 1.0, an expression language was provided compared to version 1.1 . With JSP 2.0, the JSP-EL was included in the JSP specification itself. The primary goal of JSTL 1.1 is accordingly to adapt the library to JSP-EL for JSP 2.0. Version 1.2 of the library brings the JSTL up to date with regard to the standardization of the Expression Language through the JSP 2.1 and JSF 1.2 specifications. The JSTL version 1.2 is also part of the Java EE 5 platform .

Using the JSTL 1.1

Since the JSP-EL is required for the JSTL 1.1, a servlet container must at least meet the JSP-2.0 specification so that it can be used on it. The reference implementation is divided into two JAR archives standard.jar and jstl.jar , which for most containers usually only need to be found in the lib path of the web application. To maintain backward compatibility, JSTL 1.1 is referenced by the URI http://java.sun.com/jsp/jstl/fmt , while JSTL 1.0 was http://java.sun.com/jstl/fmtused.

Example JSP page in XML notation (JSPX):

<?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="de">
<head>
  <title>JSTL 1.1</title>
</head>
<body>

<h1>Iteration</h1>

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

<h1>Formatierung</h1>

<p>
  Währung: <fmt:formatNumber value="10000" type="currency" currencyCode="EUR" />
</p>

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

Explanations of the JSP code:

The element jsp:rootshows the use of the basic and I18N taglibs (core and fmt) from the JSTL and binds them to the corresponding XML namespaces. The forEach tag from the core library is used under the heading Iteration: The tag body (that is, the content of the tag) is output here ten times. In this loop there is ${num}a JSP expression: Here the current value of 'num' is output with each loop pass. The formatNumber tag from the fmt library of the JSTL is used under the heading Formatting. Depending on the language set (this can be fmt:setLocaleset using , for example ), the number 10000 is formatted differently here (for example, it can be output in German as "EUR 10,000.00" and in English as "EUR 10,000.00").

The JSTL and Struts

In contrast to Struts - Framework JSTL is not to a specific architecture paradigm such. B. MVC bound. Both tag libraries have tags with the same name. Therefore, the unique prefix (JSP) or the namespace (JSPX) must be taken into account with mixed use.

Web links