日期:2014-05-17 浏览次数:20800 次
public class MyChooseTag extends BodyTagSupport{ private boolean executed; public void setExecuted(boolean ed){ this.executed=ed; } public boolean getExecuted(){ return executed; } public int doStartTag() throws JspException{ executed=false; return EVAL_BODY_INCLUDE; } public int doEndTag() throws JspException{ return EVAL_PAGE; } } public class MyIfTag extends BodyTagSupport{ private boolean condition; public void setCondition(boolean condition){ this.condition=condition; } public int doStartTag() throws JspException{ MyChooseTag parent=(MyChooseTag)this.getParent(); if(condition){ parent.setExecuted(true); return EVAL_BODY_INCLUDE; } else{ parent.setExecuted(false); return SKIP_BODY; } } public int doEndTag() throws JspException{ return EVAL_PAGE; } } public class MyElseTag extends BodyTagSupport{ public int doStartTag() throws JspException{ MyChooseTag parent=(MyChooseTag)getParent(); if(parent.getExecuted()){ return SKIP_BODY; } else{ return EVAL_BODY_INCLUDE; } } }