Chapter 23. Using the JSTL

Introduction

JavaServer Page’s custom tags and tag handlers are designed to help you invent your own tags. While this is a powerful tool for Java web developers, developing custom tags entails a steep learning curve and can be time consuming. Luckily, some hard-working volunteer software developers have developed a bunch of highly useful tags for you. This tag collection is called the JavaServer Pages Standard Tag Library (JSTL). The JSTL specification arises from the Java Community Process (JSR-052) and the Apache Jakarta Project has developed a JSTL implementation, the Standard 1.0 taglib.

The JSTL has very broad functionality. It includes tags that:

  1. Set object attributes for web applications (c:set ).

  2. Output text to web pages (c:out and x:out).

  3. Iterate over collections of data (c:forEach and x:forEach).

  4. Format numbers, dates, and currencies using different international styles (e.g., fmt:formatDate, fmt:formatNumber).

  5. Transform XML (x:transform ).

  6. Interact with databases using SQL (e.g., sql:query, sql:update).

  7. Allow you to embed function calls in JSP code and template text (e.g., fn:substring( )). This functionality is available only with JSP 2.0 and JSTL 1.1 (see Recipe 23.14).

The JSTL originated a very important new JSP technology, the Expression Language (EL). This is a scripting language based generally on JavaScript and other scripting tools that, with JSP 2.0, can be embedded in HTML template text.

Tip

The EL was once part of JSTL 1.0 but ...

Get Java Servlet & JSP Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.