• How to access body of Custom tags in JSP tutorial


     

    <prefix: xyz>
    Body of custom tag: This is what we will access in the below example
    </prefix:xyz>
    

      

    Example:
    In this example or custom tag will append a String to its own body and will display the result.

    Tag handler class: Details.java

    package beginnersbook.com;
    import javax.servlet.jsp.tagext.*;
    import javax.servlet.jsp.*;
    import java.io.*;
    
    public class Details extends SimpleTagSupport {
       //StringWriter object
       StringWriter sw = new StringWriter();
    
       public void doTag() throws JspException, IOException
       {
           getJspBody().invoke(sw);
           JspWriter out = getJspContext().getOut();
           out.println(sw.toString()+"Appended Custom Tag Message");
       }
    }
    

      

    TLD file: message.tld
    Remember to have this file in WEB-INF folder.

    <taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>2.0</jsp-version>
    <short-name>My Custom Tag: MyMsg</short-name>
    <tag>
    <name>MyMsg</name>
    <tag-class>beginnersbook.com.Details</tag-class>
    <body-content>scriptless</body-content>
    </tag>
    </taglib>
    

      

    JSP Page: index.jsp

    <%@ taglib prefix="myprefix" uri="WEB-INF/message.tld"%>
    <html>
    <head>
      <title>Accessing Custom Tag Body Example</title>
    </head>
    <body>
      <myprefix:MyMsg>
        Test String
      </myprefix:MyMsg>
    </body>
    </html>
    

      

    Output:

    Test String Appended Custom Tag Message
    

      

  • 相关阅读:
    Solidity字符串类型
    Solidity中如何判断mapping中某个键是否为空呢?
    CentOS7 内核模块管理
    Centos7 搭建pptp服务器
    Python实现批量执行华为交换机脚本
    CentOS7 硬盘检测
    华为交换机SOCK CPU占用率高处理方法
    CentOS7 iptables安装及操作
    CentOS7 修复grub.cfg文件
    CentOS7 修复MBR引导
  • 原文地址:https://www.cnblogs.com/hephec/p/4603549.html
Copyright © 2020-2023  润新知