import java.io.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class CustomTag extends SimpleTagSupport { private String customAttribute; public void setCustomAttribute(String customAttribute) { this. customAttribute = customAttribute; } public String getCustomAttribute() { return customAttribute; } StringWriter stringWriter = new StringWriter(); public void doTag() throws JspException, IOException { if (customAttribute != null) { // process tag attribute getJspContext().getOut().println(customAttribute); } else { // get the content from the tag body getJspBody().invoke(stringWriter); // process tag body’s content getJspContext().getOut().println(stringWriter.toString()); } } }