Custom tags are user-defined tags. By using Custom tags we can get the following advantages:
1. We can reduce the java code into a JSP page.2. We can provide security in JSP.
3. We can get the logic reusability.
4. By using the custom tag we can separate the business logic from the JSP page.
To creating any Custom Tag we need three things:
1. The Tag Handler Class.
2. The Tag Library Descriptor.
3. A JSP page.
2. The Tag Library Descriptor.
3. A JSP page.
1. The Tag Handler Class:
The Tag Handler class is a java class in which the custom tag logic is defined. For every custom tag, there should be an associated tag handler class. The number of custom tags in a JSP page is equal to the number of tag handler classes. To create a tag handler class our java class should extend one of the following two classes.
i) TagSupport Class
ii) BodyTagSupport class
ii) BodyTagSupport class
i) doStartTag()
ii) doEndTag()
2. The Tag Library Descriptor:
A TLD file is like an XML file in which custom tags are configured. The main purpose of the TLD file is to connect the Tag handler class with a tag name that will appear in the JSP document. It also gives more information to the JSP container about the tags it describes. It describes the tag attributes that can be used with the tag and tells whether they're required or are optional.3. A JSP page:
A JSP page is a page where we will be using our custom tag. In the JSP page to define some prefix for our custom tags, we use taglib directive in JSP. Using taglib directive we also define a unique identification name for the tag started with the same prefix. To add a prefix and a unique identification name we use two attributes URI and prefix.
You may also like:
Custom Tags in JSP with Example
Reviewed by Prashant Srivastava
on
December 22, 2018
Rating:
No comments: