自定义Html标签方式

首先需要定义一个.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()方法



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值