Custom tag

The custom tag in JSP is considered as the user defined JSP tag or element. The action elements and the expression language are not enough to remove the scriptlet code from the JSP page and hence for this reason custom tags are used. When the JSP is translated into the servlet the custom tags in that JSP page are converted into the operations on an object which is called tag handler. Customs are useful for the presentation of the web page and to enhance our web page. These make easer for the web author to use and to control the web page. The custom tags are reusable which means that we can use the custom tags again and again.


Format of custom tag:

A custom tag has two formats that are the custom tag can either be empty or it may contain a body. The custom tag which is empty is called Empty tag and the custom tag which contains body is a body tag. It depends on the tag handler class that how many attributes a tag will accept.


Syntax for an empty tag:

<PrefixOfTagLibrary: NameOfcustomTag attribute1= “Name of attribute1” attribute2 = “Name of attribute2” … / >


Syntax for Custom body tag:

The following is the syntax of the custom body tag:

<PrefixOfTagLibrary: NameOfcustomTag attribute1 = “Name of attribute1”

    attribute2 = “Name of attribute2” … />

< –Body of custom tag– >

</ PrefixOftagLibrary: NameOfcustomTag>

It is a good practice to create our own custom tags as the custom tags are reusable therefore, we can use them and their functionalities later in our JSP page.