首先需要定义一个.tld文件
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>c_pw</short-name>
<uri>/mytaglib</uri>
<tag>
<name>checkRight</name>
<tag-class>com.thwl.jq.nexus.util.CheckRight</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>level</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>modelId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
格式如上所示
web.xml需要加入如下配置
<jsp-config>
<taglib>
<taglib-uri>core</taglib-uri>
<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>fn</taglib-uri>
<taglib-location>/WEB-INF/fn.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>functions</taglib-uri>
<taglib-location>/WEB-INF/functions.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>s</taglib-uri>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
</taglib>
<!-- 引入自定义标签 -->
<taglib>
<taglib-uri>c_pw</taglib-uri>
<taglib-location>/WEB-INF/pw.tld</taglib-location>
</taglib>
</jsp-config>
引入这个配置文件
需要继承于SimpleTagSupport或者TagSupport
实现doTag()方法