In this section, we will discuss about how to display current date & time using custom(user define) tag.
JSP Custom Tags :Provide a mechanism to a Web programmer to reuse and encapsulate complex recurring code in a JSP application.
Provide simplicity and reusability of Java code.
Enable you to perform various functions, such as:
Accessing all implicit variables of a JSP page, such as request, response, in, and out.
Modifying the response generated by a calling JSP page.
The various types of custom tags that you can develop in JSP are :
<td:welcome />
<td: welcome color=?blue?></td:welcome>
Tags with a body: Refer to the custom tag within which you can define nested
custom tags, scripting elements, actions, HTML text, and JSP
directives. The following code snippet shows a custom tag that contains a JSP
scripting element as its body:
<td: welcome>
<%=today_date%>
</td:welcome>
Nested tags: Refer to the set of custom tags in which one custom tag encloses one or more custom tags. The following code snippet shows a nested custom tag:
<td1:ifTag condition ?<%=eval>? >
<td2:valueTrue>
The expression evaluates to true
</td2:valueTrue>
</td1:ifTag>
Development of Custom Tag :
To develop a custom tag, you need to perform following steps:
Develop a tag handler or class file(.java)
Develop the Tag Library Descriptor (TLD) file
Include the Tag Library in a JSP page
EXAMPLE :
In this Example, Current date & time will display using custom tag.
Tag Handler File :
Build a class that implements the
javax.servlet.jsp.tagext tag interface as follows. Compile it and place it
under the web-inf/classes directory (in the appropriate package structure).
package foo; |
Tag Library Descriptor (TLD) file : Now we need to describe the tag, so create a file called "taglib.tld" and place it under the web-inf directory.
<taglib> |
JSP file :
<html> |
Deployment of application (OUTPUT) :

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.