Taglibs [Part 1]: Introduction
Short intro TagLibs
- The Tag Libraries/JSP Tag Libraries have been developed to be integrated and used in JSP pages of a J2EE application.
- A Taglib will run a series of actions intended to be used in a JSP form tags or XML tags. These actions manipulate data and variables of the JSP page and the JAVA J2EE application.
- A TagLib is defined by a taglib descriptor or Tag Libraries Descriptor and Java classes that implement the JSP Tag interface.
- This descriptor is represented by an XML file extension ( .tld) describing the links between the tags and Java classes. Any XML tag written in a JSP page calls for such actions. These tags are replaced only during the compilation of the JSP on the application server by calling the corresponding Java classes.
- Below is an example of standard tags prefixed with jsp:
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
A taglib therefore optimizes the Java code to write in a JSP page.
A Taglib is represented by three components:
- Tag Library Descriptor, a .tld file extension, which defines the relationship between tags and the associated Java classes.
- The Java classes that implement the various cad Tag/ Tag interface, or one of its interfaces (BodyTag or IterationTag).
- The Java classes that implement TagExtraInfo to return additional data on the tags, but this is optional.
Frameworks based on Taglibs
In order to optimize the JAVA code for JAVA J2EE application, you can multiple frameworks such as Struts, SpringMVC, JSTL.
JSTL, developed by Sun, provides a standard library for the most basic functionality of a JAVA J2EE application, and most taglibs currently present extend the JSTL library. It is for this reason that JSTL is used as a basic framework to use the native API from Sun.
Different versions of Taglib
There are currently three versions of taglibs.
For each TagLib version, there is a J2EE and JSP:
Taglib J2EE JSP
1.1 1.2.1 1.1
1.2 1.3 1.2
2.0 1.4 2.0
- The latest version is 2.0. and is not yet supported by the publishers.
- Version 1.2, is mostly used.
- Both versions are supported by Java 1.5.
Thanks to n00r for this tip