Servlet提供自定义标签不需要注册,如下几步实现:
1、extends SimpleTagSupport 类,OverWriter doTag()
2、按规范写 *.tld 文件 (MyTag.tld)
3、引用

继承 SimpleTagSupport 类,重写 doTag() 方法
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
在 Jsp 中引用标签
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%@ taglib uri="com.tag.MyTag" prefix="myTag" %> <!-- 这里申明标签 -->
3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <html>
5 <body>
6 <!-- 这里使用标签 -->
7 <myTag:MyTag name="Welcome:" value="admin"/>
8 </body>
9 </html>