Académique Documents
Professionnel Documents
Culture Documents
@Override
public void doTag() throws JspException, IOException {
try {
JspWriter out = getJspContext().getOut();
//logic
} catch (Exception e) {
e.printStackTrace();
}
}
}
Step#2 Create Tag Library Descriptor (TLD) file under WEB-INF folder
<taglib>
<tlib-version>1.3</tlib-version>
<jsp-version>2.1</jsp-version>
<short-name>_______</short-name>
<uri>______________</uri>
<tag>
<name>__TAG NAME_____</name>
<tag-class>__TAG HANDLER FULLY QULIFIED CLASS NAME ___</tag-class>
<body-content>empty/scriptless/jsp</body-content>
<attribute>
<name>_attribute name__</name>
<required>true/false</required>
</attribute>
</tag>
</taglib>
Step#3 Import Tag Library in UI(JSP) file using
<%@taglib prefix="__" uri="___" %>
Step#4 Use tag in JSP
<prefix:tagName attribute1="val1" attribute2="val2" .../>
1|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET, HYD
import java.io.IOException;
import java.util.Date;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
@Override
public void doTag() throws JspException, IOException {
try {
JspWriter out = getJspContext().getOut();
out.print("Sathya Technologies,Ameerpet,Hyd "+new
Date());
} catch (Exception e) {
e.printStackTrace();
}
}
}
b. TLD file : sample.tld
<taglib>
<tlib-version>1.3</tlib-version>
<jsp-version>2.1</jsp-version>
<short-name>SATHYA TLD</short-name>
<uri>http://sathyatech.org/addr-tld</uri>
<tag>
<name>address</name>
<tag-class>com.app.tag.MyAddressTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
c. JSP File : index.jsp
<%@taglib prefix="sathya" uri="http://sathyatech.org/addr-
tld" %>
<html>
<body>
<sathya:address/>
</html>
2|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET, HYD
import java.io.IOException;
import java.io.StringWriter;
import java.util.Date;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
@Override
public void doTag() throws JspException, IOException {
try {
JspWriter out = getJspContext().getOut();
out.print(new Date());
out.println("<br/>Sathya
Technologies,Ameerpet,Hyderabad");
StringWriter str=new StringWriter();
//read body into str and print
getJspBody().invoke(str);
out.println("<br/> Details:"+str.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<tag>
<name>address</name>
3|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET, HYD
<tag-class>com.app.tag.MyAddressTag</tag-class>
<body-content>scriptless</body-content>
</tag>
</taglib>
c. JSP File : index.jsp
<%@taglib prefix="sathya" uri="http://sathyatech.org/addr-tld" %>
<html>
<body>
<sathya:address>
Contact : 040-2312313
</sathya:address>
</html>
import java.io.IOException;
import java.io.StringWriter;
import java.util.Date;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
4|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET, HYD
@Override
public void doTag() throws JspException, IOException {
try {
JspWriter out = getJspContext().getOut();
out.print(new Date());
out.println("<br/>Sathya
Technologies,Ameerpet,Hyderabad");
StringWriter str=new StringWriter();
//read body into str and print
getJspBody().invoke(str);
out.println("<br/> Details:"+str.toString());
out.println("<br/> Extra
Details:"+contact+","+info);
} catch (Exception e) {
e.printStackTrace();
}
}
}
b. TLD file : sample.tld
<taglib>
<tlib-version>1.3</tlib-version>
<jsp-version>2.1</jsp-version>
<short-name>SATHYA TLD</short-name>
<uri>http://sathyatech.org/addr-tld</uri>
<tag>
<name>address</name>
<tag-class>com.app.tag.MyAddressTag</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>contact</name>
<required>true</required>
</attribute>
<attribute>
<name>info</name>
<required>false</required>
</attribute>
</tag>
</taglib>
c. JSP File: index.jsp
<%@taglib prefix="sathya" uri="http://sathyatech.org/addr-tld" %>
<html>
<body>
5|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET, HYD
FB : https://www.facebook.com/groups/thejavatemple/
6|Page