Taglib Directive in JSP

How is Taglib Directive used in JSP?


Taglib directive is used to define the tag library which is a collection of tags. A Tag library can be a standard(pre-defined) or a custom(user-defined) one. The "prefix" attribute is a must for custom as well as standard tags in jsp.


<%@ taglib uri="URIToTagLibrary" prefix="tagPrefix" %>

Example :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<p>Simple Example for C:out</p>
Multiply 5 and 2::<c:out value="${5*2}" />
Result :

Simple Example for C:out
Multiply 5 and 2::10

In the above example the "taglib" directive points to the core tag library of JSTL or JSP Standard tag library using the "uri" attribute "http://java.sun.com/jsp/jstl/core", the prefix used in the taglib directive will be "c" for core tag library. If a custom tag library is used then the prefix can be chosen by the user.

Ask Questions

Ask Question