简单标签-实现自定义标签除了移除java代码的其他四个功能

本文介绍了使用JSP简单标签支持类(SimpleTagSupport)来实现不同功能的方法,包括控制标签体是否执行、重复输出标签体、修改标签体内容使其全部转为大写以及跳过页面后续处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/控制标签体是否执行
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就是无脚本代码的意思



转载于:https://www.cnblogs.com/08love125/articles/5443466.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值