JSP taglib Directive



JSP taglib Directive

  1. Using JSP API’s we can define custom JSP tags like HTML or XML tags.
  2. JSP tag library is a set of user-defined tags which are used for the implementation of the custom behavior.
  3. JSP taglib directive is used to -
    • Declare set of custom tags
    • Identify the location of the library
    • Provide a way for identifying the custom tags

Syntax :

We can write taglib directive using below syntax -

<%@ taglib uri="uri" prefix="tagPrefix" >
AttributePurpose
uriUsed to define the URL of the TAG library
prefixUsed to define the prefix of the TAG library

XML equivalent syntax -

<jsp:directive.taglib uri="uri" prefix="tagPrefix" />

Example :

Suppose the userlibrary tag library contains a tag called print. We can use the hello tag with a prefix of mytag, using syntax

<%@ taglib uri = "http://www.c4learn.com/userlibrary" 
    prefix = "mytag" %>
<html>
<body>
  <mytag:print/>
</body>
</html>