1銆乪xtends SimpleTagSupport 綾伙紝OverWriter doTag()
2銆佹寜瑙勮寖鍐?*.tld 鏂囦歡 錛圡yTag.tld錛?br />
3銆佸紩鐢?/div>

緇ф壙 SimpleTagSupport 綾伙紝閲嶅啓 doTag() 鏂規(guī)硶
1 package com.tag;
2 import java.io.IOException;
3
4 import javax.servlet.jsp.JspContext;
5 import javax.servlet.jsp.JspException;
6 import javax.servlet.jsp.JspWriter;
7 import javax.servlet.jsp.tagext.SimpleTagSupport;
8
9
10 public class MyTag extends SimpleTagSupport{
11
12 private String name ;
13 private String value ;
14
15 public void setName(String name) {
16 this.name = name;
17 }
18
19 public void setValue(String value) {
20 this.value = value;
21 }
22
23 @Override
24 public void doTag() throws JspException, IOException {
25 JspContext jspContext = getJspContext();
26 JspWriter out = jspContext.getOut() ;
27 out.print(this.name + this.value);
28 super.doTag();
29 }
30
31 }
32 
鎸夎鑼冨啓 MyTag.tld
1 <?xml version="1.0" encoding="UTF-8"?>
2 <taglib>
3 <tlib-version>1.0</tlib-version>
4 <jsp-version>2.0</jsp-version>
5 <uri>com.tag.MyTag</uri>
6 <tag>
7 <name>MyTag</name>
8 <tag-class>com.tag.MyTag</tag-class>
9 <body-content>empty</body-content>
10 <attribute>
11 <name>name</name>
12 <required>true</required>
13 </attribute>
14 <attribute>
15 <name>value</name>
16 <required>true</required>
17 </attribute>
18 </tag>
19 </taglib