练习有父标签的和两个标签之间通信(通过父标签) <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:自定义标签之开发<c:if><c:else>标签
最新推荐文章于 2024-06-12 15:00:08 发布