简单标签-实现自定义标签除了移除java代码的其他四个功能
/控制标签体是否执行 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文件-》<body-content>JSP</body-content>
在简单标签为<body-content>scriptless</body-content>scriptless就是无脚本代码的意思
现在的几乎什么都不懂,但是不代表以后的我也是这样。