<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE taglib
\"http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd\">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>MyTagLib</short-name>
<tag>
<name>showDataTag</name>
<tag-class>demo.tag.TagDemo</tag-class>
<attribute>
<name>pageSize</name>
<required>true</required>
<type>Integer</type>
</attribute>
</tag>
</taglib>
1. 标签库描述文件必须以 tld 为 文件的后缀名
2. 标签库描述文件应该遵守 xml 语法要求
3. 标签库描述文件的根元素 必须是 <taglib>
4. taglib根元素下必须完成以下四个子元素
tlib-version : jsp-version: short-name: 标签库描述文件的简要说明,且只能出现一次
tag: 能出现一到多次 , 描述标签库中的标签名及你要对应的标签处理类
5. tag元素下出现的子元素:
name子元素:标签名
tag-class子元素:对应的标签处理类
attribute子元素:该标签应包含的属性
6. attribute元素下出现的子元素:
name:属性名
required:该属性名可不可省略
type:标签处理类中相关属性的类型
5.在web.xml引入标签库描述文件
<?xml version=\"1.0\" encoding=\"UTF-8\"?> [Page]
<web-app version=\"2.4\"
xmlns=\"http://java.sun.com/xml/ns/j2ee\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd\">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>MyFirstTag</taglib-uri>
<taglib-location>/WEB-INF/MyTagLib.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
1. 在web.xml中实现taglib元素的子元素:
taglib-location: 标签库描述文件在Web应用中的相对路径
<taglib-location>/WEB-INF/MyTagLib.tld</taglib-location>
taglib-uri:该标签库在JSP中用什么名字来调用
<taglib-uri>abc</taglib-uri>
2. 在要调用标签库的JSP中声明
声明:<%@ taglib uri=\"MyFirstTag\" prefix=\"suibian\" %>
调用:<suibian:showDataTag pageSize=\"10\"></suibian:showDataTag>
