/控制标签体是否执行public class SimpleDemo1 extends SimpleTagSupport{ @Override public void doTag() throws JspException, IOException { //拿到标签体 JspFragment jf=this.getJspBody(); //jf.invoke(this.getJspContext().getOut());拿到标签体不输出就不会显示该标签体 } }
//控制标签体重复输出public class SimpleDemo2 extends SimpleTagSupport{ @Override public void doTag() throws JspException, IOException { //拿到标签体 JspFragment jf=this.getJspBody(); for(int i=0;i<5;i++){ //想当于jf.invoke(this.getJspContext().getOut()); jf.invoke(null);//默认输给浏览器 } } }
//修改标签体,--》大写public class SimpleDemo3 extends SimpleTagSupport{ @Override public void doTag() throws JspException, IOException { //拿到标签体 JspFragment jf=this.getJspBody(); StringWriter sw=new StringWriter(); jf.invoke(sw); String value=sw.toString().toUpperCase(); this.getJspContext().getOut().write(value); } }
//用简单标签实现是否实现标签体后的jsp代码public class SimpleDemo4 extends SimpleTagSupport{ @Override public void doTag() throws JspException, IOException { throw new SkipPageException(); } } 注意:在传统标签中有标签实体时:tld文件-》JSP 在简单标签为scriptless scriptless就是无脚本代码的意思