JSP:自定义标签之标签

 

public class IfTag extends SimpleTagSupport {

         private boolean test;

 

         public void setTest(boolean test) {

                   this.test = test;

         }

 

         @Override

         public void doTag() throws JspException, IOException {

                   // TODO Auto-generated method stub

                   if(test)//如果有EL表达式就会先执行

                            this.getJspBody().invoke(null);

                   else

                            super.doTag();

                  

         }

}

  <body>

 <% session.setAttribute("user","mmmm") ;%>

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

    未登陆. <br>

    </fix:if>

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

   welcome用户已经登录. <br>

    </fix:if>

   

    ssss

  </body>

    <tag>

        <description>Outputs Hello, World</description>

        <name>if</name>

        <tag-class>cn.itcast.web.tag.example.IfTag</tag-class>

        <body-content>scriptless</body-content>

        <attribute>

                 <name>test</name>

                 <required>true</required>

                 <rtexprvalue>true</rtexprvalue>

        </attribute>

    </tag>

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