[转][Java]简单标签库简介

public class SimpleTagDemo extends SimpleTagSupport {
    @Override
    public void doTag() throws JspException, IOException {
        JspFragment jf = this.getJspBody();
        // 下面两句效果相同,都是把标签体重复 5 次
        for(int i=0;i<5;i++){
            jf.invoke(this.getJspContext().getOut());
            //jf.invoke(null);
        }
    }
}

以上代码也能达到重复 5 次标签体内容的效果。

public class SimpleTagDemo extends SimpleTagSupport {
    @Override
    public void doTag() throws JspException, IOException {
        JspFragment jf = this.getJspBody();
        StringWriter sw = new StringWriter();
        jf.invoke(sw);

        String content = sw.toString();
        content = content.toUpperCase();
        this.getJspContext().getOut().write(content);
    }
}

以上代码也能达到修改标签体效果

posted on 2017-06-07 00:17  z5337  阅读(133)  评论(0)    收藏  举报