Learn Java for Web Development

(Tina Meador) #1

128 CHAPTER 3: Best Practices in Java EE Web Development


JSTL

The ultimate goal of the JSP Standard Tag Library (JSTL) is to help simplify the development of
Java Server Pages. As discussed in the previous section, scriptlets lead to unmaintainable JSPs
and can be replaced by JSP standard actions. However, standard actions are far too limited; an
even better approach is for Java developers to create their own custom actions. Still, creating a
custom action is a nontrivial task. JSTL provides such custom actions that can handle common
recurring tasks, and JSTL includes a wide variety of actions divided into different functional areas.
Table 3- 4 lists the functional areas along with the URIs used to reference the libraries and the
prefixes used in the JSTL specification.


Table 3-4. JSTL Tag Libraries


Functional Area URI Prefix

Core http://java.sun.com/jsp/jstl/core c
XML processing http://java.sun.com/jsp/jstl/xml x
I18N-capable formatting http://java.sun.com/jsp/jstl/fmt fmt
Relational database access http://java.sun.com/jsp/jstl/sql sql
Functions http://java.sun.com/jsp/jstl/functions fn

Figure 3-8. Output from invoking the EL function


Many JSTL actions export scoped variables that you can easily access through the Expression
Language. As we saw in the previous chapter, scoped variables are objects stored in one of the
JSP scopes: application, page, request, and session. When a JSTL action makes a scoped variable

Free download pdf