Home

 

Tag libraries

Tag libraries are a standard way of packaging tag extensions for applications using JSPs.

Tag extensions address the problem that arises when a developer wants to use non-trivial processing logic within a JSP. Java code can be embedded directly in the JSP using the standard tags described before. This mixture of HTML and Java makes it difficult to separate development responsibilities (the HTML/JSP designer has to maintain the Java code) and makes it hard to use appropriate tools for the tasks in hand (a page design tool will not provide the same level of support for Java development as a Java development tool). This is essentially the reverse of the problem described when discussing these servlets. To address this problem, developers have documented the View Helper design pattern, as described in Core J2EE Patterns: Best Practices and Design Strategies by Crupi, et al. The pattern catalog contained in this book is also available at:

http://java.sun.com/blueprints/corej2eepatterns

Tag extensions are the standard way of implementing View Helpers for JSPs.
Using tag extensions, a Java developer can create a class that implements some view-related logic. This class can be associated with a particular JSP tag using a tag library descriptor (TLD). The TLD can be included in a Web application, and the tag extensions defined within it can then be used in JSPs. The JSP designer can use these tags in exactly the same way as other (standard) JSP tags. The JSP specification includes classes that can be used as a basis for tag extensions and a simplified mechanism for defining tag extensions that does not require detailed knowledge of Java.

Many convenient tags are provided in the JSP Standard Tag Library (JSTL), which actually includes several tag libraries:

Core tags: Flow control (such as loops and conditional statements) and various general purpose actions

XML tags: Allow basic XML processing within a JSP

Formatting tags: Internationalized data formatting

SQL tags: Database access for querying and updating

Function tags: Various string handling functions

Tag libraries are also available from other sources, such as those from the Jakarta Taglibs Project (http://jakarta.apache.org/taglibs/), and it is also possible to develop tag libraries yourself.

ibm.com/redbooks