JSP The taglib Directive

The JavaServer Pages API allow you to define custom JSP tags that look like HTML or XML tags and a tag library is a set of user-defined tags that implement custom behavior.

Thetaglibdirective declares that your JSP page uses a set of custom tags, identifies the location of the library, and provides means for identifying the custom tags in your JSP page.

The taglib directive follows the syntax given below

Where, theuriattribute value resolves to a location the container understands and theprefixattribute informs a container what bits of markup are custom actions.

You can write the XML equivalent of the above syntax as follows

When you use a custom tag, it is typically of the formprefix:tagname. The prefix is the same as the prefix you specify in the taglib directive, and the tagname is the name of a tag implemented in the tag library.

For example, suppose thecustlibtag library contains a tag calledhello. If you wanted to use the hello tag with a prefix ofmytag, your tag would bemytag:helloand it will be used in your JSP file as follows

We can call another piece of code usingmytag:hello. We will see how to develop our custom tags and how to use them inJSP – Custom Tagstutorial.