In Terms JSP, What is taglib Directives?

The taglib Directives
A tag library quite simply contains a collection of actions (also known as tags) that can be grouped together to perform some form of logic. These actions are XML-based so their use is considerably easier for a non-Javaspeaking UI designer. Of course another major benefit is that they can encapsulate large amounts of programmatic logic into a single line of code, which is a much better solution in terms of readability and maintainability and of course reuse, when compared to the ugly scriptlet-based approach you saw earlier.

Tag libraries come in two different flavors these days. The first is custom tag libraries, which have generally been put together by the development team or acquired from another team or project or even the Internet,and as of JSP 2.0, the JSTL, which contains a set of useful actions that are applicable to almost every web application in use today in some form.

To make use of a custom tag library, the web container needs to be made aware of specific information about the library itself. A special file called a tag library descriptor (TLD) is used for this purpose. The XML-based TLD file is used to provide general descriptive information about the custom tag library, such as a description of its usage and the JSP version that the tag supports. More importantly, the TLD file contains important information about each of the custom actions or tags that are included inside the tag library, such as which attributes are permitted by which tags, whether the tags accept body content, and so on.

Once the JSP container is made aware of the TLD for a particular custom tag library, the JSP developer can make use of any of the tags declared inside the library. Like custom Java classes (in fact, any class that doesn't reside in the core java.lang package), tag libraries must be imported into the page before they can be used. You've seen that Java classes are imported into a JSP page by using a JSP page directive, and in a similar fashion, tag libraries are imported using the taglib directive.


The syntax for the taglib directive is as follows:
<%@ taglib uri="/tagLibraryURI" prefix="tagPrefix" %>

No comments:

Post a Comment