您的位置:首页 > Web前端 > JavaScript

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

2015-11-25 09:09 537 查看
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>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: