Write a TAG involving three steps,
(1) Write JSP
(2) Write a java program for TAG
(3) Write a description file of the TAG library TLD (actually an XML file)
There is no order between these three steps, and below is a simple example:
1 Write hellotag.jsp
<% @ Page ContentType = "Text / HTML"%>
<% @ Taglib Uri = "/ Web-INF / CLASS / TAGS / HELLOTAG.TLD" prefix = "Hello"%>
body>
html>
2 Write TAG
Hellotag.java
Package tags; // Note: must be placed in a package
Import java.io. *;
Import javax.servlet.jsp. *;
Import javax.servlet.jsp.tagext. *;
Public class hellotag extends tagsupport {
Public int desarttag () {
Try {
// Get the output object of JSP using JSPWriter
Jspwriter jspwriteroutput = pageContext.getOut ();
JspwriterOutput.print ("Hello Tag!");
} Catch (ioexception oEx) {
System.out.println ("IOEXCEPTION in Hellotag" IOEX);
}
Return (SKIP_BODY);
}
}
3 Write hellotag.tld
This is the description of the Tag library:
XML Version = "1.0" encoding = "UTF-8"?>
DOCTYPE TAGLIB
PUBLIC "- // Sun microsystems, Inc.//dtd JSP Tag Library 1.2 // en"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
description>
tag>
taglib>
4 Note:
Usually manually write XML files, but Sun's tutorial recommends writing custom TAGs using IDE tools, such as NetBeans
Generally, put the TLD file directly in the web-inf directory.
references:
Http://java.sun.com/j2ee/1.4/docs/tutorial/doc/jspintro10.html