Three simple examples to illustrate custom tag development

There is three examples in this practice. You can check how they are exist at the same time in an application.
1. Tag File
Header.tag

<[email protected] description="put the tag description here" pageEncoding="UTF-8"%>
 
<%-- The list of normal or fragment attributes can be specified here: --%>
<[email protected] name="fontColor" required="true"%>
<[email protected] body-content="tagdependent" %>
 
<%-- any content can be specified here e.g.: --%>
<em><strong><font color="${fontColor}">
    <jsp:doBody/>
 
</font></strong></em><br>

index.jsp

<[email protected] contentType="text/html" pageEncoding="UTF-8"%>
<[email protected] prefix="myTags" tagdir="/WEB-INF/tags" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello< World!</h1>
        <myTags:Header fontColor="blue">
            Schedule a java task to run at a certain time, and wrap it as a windows service
            Written by admin on August 21, 2009 — Leave a Comment [edit]
            Make a Java program that run at a certain time is not difficult just use java.util.Timer and java.util.TimerTask classes, here is the code.
        </myTags:Header>
    </body>
</html>

2. Simple tag Handler
TestSimpleTag.java

package test;
 
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
 
 
public class TestSimpleTag extends SimpleTagSupport{
    public void doTag() throws JspException, IOException{
        getJspContext().getOut().print("This is testing of a simple custom tag");
    }
}

test.tld

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
  <tlib-version>1.0</tlib-version>
  <short-name>test</short-name>
  <uri>simpleTags</uri>
  <tag>
      <name>simpleOne</name>
      <tag-class>test.TestSimpleTag</tag-class>
      <body-content>empty</body-content>
  </tag>
</taglib>

index.jsp

<[email protected] contentType="text/html" pageEncoding="UTF-8"%>
<[email protected] prefix="myTags" tagdir="/WEB-INF/tags" %>
<[email protected] prefix="testTags" uri="simpleTags" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello< World!</h1>
        <myTags:Header fontColor="blue">
            Schedule a java task to run at a certain time, and wrap it as a windows service
            Written by admin on August 21, 2009 — Leave a Comment [edit]
            Make a Java program that run at a certain time is not difficult just use java.util.Timer and java.util.TimerTask classes, here is the code.
        </myTags:Header>
        <testTags:simpleOne/>
    </body>
</html>

3. Classic Tag Handler
TestClassicTag.java

package test;
 
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
 
public class TestClassicTag extends TagSupport{
    @Override
    public int doStartTag() throws JspException{
        JspWriter out = pageContext.getOut();
 
        try{
            out.println("classic tag output");
        }catch(IOException e){
            throw new JspException("IOException- " + e.toString());
        }
 
        return SKIP_BODY;
    }
}

test.tld

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
  <tlib-version>1.0</tlib-version>
  <short-name>test</short-name>
  <uri>simpleTags</uri>
  <tag>
      <name>simpleOne</name>
      <tag-class>test.TestSimpleTag</tag-class>
      <body-content>empty</body-content>
  </tag>
  <tag>
      <name>classicOne</name>
      <tag-class>test.TestClassicTag</tag-class>
      <body-content>empty</body-content>
  </tag>
</taglib>

index.jsp

<[email protected] contentType="text/html" pageEncoding="UTF-8"%>
<[email protected] prefix="myTags" tagdir="/WEB-INF/tags" %>
<[email protected] prefix="testTags" uri="simpleTags" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello< World!</h1>
        <myTags:Header fontColor="blue">
            Schedule a java task to run at a certain time, and wrap it as a windows service
            Written by admin on August 21, 2009 — Leave a Comment [edit]
            Make a Java program that run at a certain time is not difficult just use java.util.Timer and java.util.TimerTask classes, here is the code.
        </myTags:Header>
        <testTags:simpleOne/>
        <br>
        <testTags:classicOne/>
    </body>
</html>
Category >> JSP/JSF  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>