JSP:自定义标签之开发标签

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

<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);

                   }                

         }

}

你可能感兴趣的:(JSP:自定义标签之开发标签)