1) 使用自定义标签控制页面内容(标签体)是否输出,利用doStartTag()的返回值控制
return this.SKIP_BODY; //忽略标签体
return this.EVAL_BODY_INCLUDE; //执行标签体
2) 控制整个jsp的输出
利用doEndTag()的返回值控制
return this.SKIP_PAGE; //跳过页面标签后余下的jsp代码
return this.EVAL_PAGE; //继续执行余下jsp代码
3) 自定义标签实现内容(标签体)循环输出
利用Tag子接口Iteration中定义的doAfterBody()和返回值EVAL_BODY_AGAIN,SKIP_BODY实现
a) 先覆盖doStartTag()方法,返回EVAL_BODY_INCLUDE
b) 覆盖doAfterBody()
public int doAfterBody() throws JspException { times++; int result = this.EVAL_BODY_AGAIN; if(times>4){ result = this.SKIP_BODY; } return result; } |
1) 自定义标签修改内容(标签体)EVAL_BODY_BUFFERED;
标签处理类:
a) 继承BodyTagSupport
b) 覆盖doStartTag(),并返回EVAL_BODY_BUFFERED;
c) 覆盖doEndTag()
public int doEndTag() throws JspException { BodyContent bc = this.getBodyContent(); String c = bc.getString(); c = c.toUpperCase();
JspWriter out = this.pageContext.getOut(); try { out.write(c); } catch (IOException e) { throw new RuntimeException(e); }
return this.EVAL_PAGE; } |