简单标签的使用

3 篇文章 0 订阅
 

1)使用自定义标签控制页面内容(标签体)是否输出

public void doTag() throws JspException, IOException {

      // TODO Auto-generated method stub

      //JspFragment jf=this.getJspBody();//得到标签体对象

      //jf.invoke(this.getJspContext().getOut());

      //jf.invoke(null);

}

2)简单标签控制该自定义标签后的JSP内容是否执行

创建一个标签处理器:

      public void doTag() throws JspException, IOException {

           // TODO Auto-generated method stub

           //JspFragment jf=this.getJspBody();

           //jf.invoke(null);如果没有标签体,抛异常

           throw new SkipPageException();

      }

tld文件进行描述

3)简单标签控制迭代

创建一个标签处理器

public void doTag() throws JspException, IOException {

           // TODO Auto-generated method stub

           JspFragment jf=this.getJspBody();

           for(int i=0;i<count;i++)

                 jf.invoke(null);

}

增加一个属性:count

private int count;

public void setCount(int count) {

      this.count = count;

}

tld文件进行描述

"10"

<csdn:demo8 count="${data}">

"<%=data+1%>"  rt runtime

4)简单标签控制标签体的内容进行修改

创建一个标签处理器

public void doTag() throws JspException, IOException {

      // TODO Auto-generated method stub

      JspFragment jf=this.getJspBody();

          

      //

      StringWriter sw=new StringWriter();

      jf.invoke(sw);

          

      String content=sw.toString().toUpperCase();

          

      JspWriter jw=this.getJspContext().getOut();

      jw.write(content);

          

}

tld文件进行描述

二、带属性的标签

<csdn:demo8 count="8">

 

</csdn:demo8>

标签处理器中一定也得包含一个私有的属性count和setter方法

doTag()包含业务逻辑代码

 

tld文件:

<tag>

<name></name>

<tag-class>com.hbsi.web.tag.SimpleTagDemo8</tag-class>

<body-content></body-content>

<attribute>

      <name></name>

      <required>true|false</required>

      <rtexprvalue>true|false</rtexprvalue>

</attribute>

</tag>

 

 

<csdn:demo10 date="2011-11-12"/>

 

SimpleTagDemo10:

Date date   setDate(Date d)

 

IfTag:

boolean test;

setTest()

 

doTag():  if(test){

           获取标签体,invoike()

      }

 

共享一个变量boolean

<c:choose>

<c:when test="${user!=null}">

    This is my JSP page. <br>

</c:when>

<c:other>

bbbbb

</c:other>

</c:choose>

 

<c:foreach>

</c:foreach>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值