Home » Attributes in JSP Custom Tag

Attributes in JSP Custom Tag

by Online Tutorials Library

Attributes in JSP Custom Tag

There can be defined too many attributes for any custom tag. To define the attribute, you need to perform two tasks:

  • Define the property in the TagHandler class with the attribute name and define the setter method
  • define the attribute element inside the tag element in the TLD file

Let’s understand the attribute by the tag given below:

Here m is the prefix, cube is the tag name and number is the attribute.


Simple example of attribute in JSP Custom Tag

In this example, we are going to use the cube tag which return the cube of any given number. Here, we are defining the number attribute for the cube tag. We are using the three file here:

  • index.jsp
  • CubeNumber.java
  • mytags.tld

index.jsp

CubeNumber.java

mytags.tld

Output


JSP Custom Tag attribute example with database

Let’s create a custom tag that prints a particular record of table for the given table name and id.

So, you have to have two properties in the tag handler class.

PrintRecord.java

m.tld

index.jsp

Output

jsp custom tag attribute example/> <div id= download this example

You may also like