JSP:自定义标签之开发<c:if><c:else>标签

练习有父标签的和两个标签之间通信(通过父标签)

<fix:choose>

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

                                          未登陆. <br>

         </fix:when>

         <fix:otherwith>

              welcome用户已经登录. <br>

         </fix:otherwith>

</fix:choose>

<fix:choose>

         <fix:when test="${2==2}">

        2==2<br>

         </fix:when>

         <fix:otherwith>

            2!=2<br>

         </fix:otherwith>

</fix:choose>

 

<fix:choose>

         <fix:when test="${1==1}">

         1==1 <br>

         </fix:when>

         <fix:otherwith>

             1<>1 <br>

         </fix:otherwith>

</fix:choose>

public class Choose extends SimpleTagSupport {

         private boolean isDo;

         public boolean isDo() {

                   return isDo;

         }

         public void setDo(boolean isDo) {

                   this.isDo = isDo;

         }

         @Override

         public void doTag() throws JspException, IOException {

                   this.getJspBody().invoke(null);

         }

}

public class WhenTag extends SimpleTagSupport {

 

         private boolean test;

        

         public void setTest(boolean test) {

                   this.test = test;

         }

 

         @Override

         public void doTag() throws JspException, IOException {

                   Choose parent=(Choose) this.getParent();

                   if(test && !parent.isDo())

                   {

                            this.getJspBody().invoke(null);

                            parent.setDo(true);

                   }                

         }

}

public class OtherwithTag extends SimpleTagSupport {

 

         @Override

         public void doTag() throws JspException, IOException {

                  Choose parent=(Choose) this.getParent();

                   if(!parent.isDo())

                   {

                            this.getJspBody().invoke(null);

                            parent.setDo(true);

                   }                

         }

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值