taglib的主要作用就是:对一些需要重复利用的代码段进行封装,并设置该代码段可能用到的属性,提高代码的利用率。taglib主要有三个部分构成:
1.实现代码段的.java文件;
2.标签库描述文件.tld;
3.web.xml的配置;
配置web.xml
<jsp-config>
<taglib>
<taglib-uri>http://localhost/cms</taglib-uri>
<taglib-location>/WEB-INF/cms.tld</taglib-location>
</taglib>
</jsp-config>
jspy应用标签库:
<%@ page language="java" pageEncoding="GB2312"%>
<%@ taglib uri="http://localhost/cms" prefix="cms" %>
<html>
<head>
<title>JSP taglib starting page</title>
</head>
<body>
<center>
<cms:image href="http://www.sohu.com"></cms:image>
</center>
</body>
</html>
配置标签库cms.tld
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>cms</shortname>
<tag>
<name>image</name>
<tagclass>com.kong.wap.plat.wapconstructor.constructor.taglib.image.WapCmsImageTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>src</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>alt</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>href</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>newLine</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>