自定义JSTL Tag

<?xml version="1.0" encoding="UTF-8" ?>    
<taglib 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-jsptaglibrary_2_0.xsd"
    version="2.0">         
  <tlib-version>1.0</tlib-version>  
  <short-name>fsc</short-name>  
  <uri>http://www. zu.com/core</uri>
     
  <tag>
        <name>checkbox</name>
        <tag-class>com.zu.tags.CheckBoxTag</tag-class>
        <body-content>empty</body-content>
        <attribute>
              <name>label</name>
              <required>true</required>
              <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
              <name>name</name>
              <required>true</required>
              <rtexprvalue>false</rtexprvalue>
        </attribute>        
         <attribute>
              <name>value</name>
              <required>true</required>
              <rtexprvalue>true</rtexprvalue>
        </attribute>           
  </tag>
</taglib> 

复习常用JSTL Tag 为什么需要自定义Tag:简化html的拼接生成

如何自定义Function,例子: 编写一个类继承自:SimpleTagSupport

重写doTag方法

JspWriter out = this.getJspContext().getOut()获得out对象,可以输出jsp内容

实现一个包含了label的checkbox,属性:label、value、name、id。

在项目下新建一个META-INF文件夹,建一个tld文件→。一个tld文件中可以建多个tag节点。required表示这个属性是否必须被赋值;rtexprvalue表示是普通属性还是需要用EL赋值(演示不同的赋值方式)

猜你喜欢

转载自www.cnblogs.com/traveller-hzq/p/9193124.html
tag