In this tutorial you will learn about the empty custom tag in jsp.
Custom tag empty
In this tutorial you will learn about the empty custom tag in jsp.
A Custom tag is called an empty tag when it doesn't contain any attribute or body. In a jsp page an empty tag can be written as :
<dev:mytag3/> or <dev:mytag3></dev:mytag3>
According to the above mentioned you can say that it is equivalent to a jsp page having a body with no content in it (white space are ignored).
Example :
In the example given below you will see that the custom tag in jsp page is not containing any attribute or body. So when you will execute the jsp page there will nothing be displayed concern to custom tag written on jsp page there will only the body content of jsp page and tag handler class's doStartTag() content written in print() method be displayed.
SimpleTagHandler3.java
package pack; import javax.servlet.jsp.tagext.TagSupport; import javax.servlet.jsp.tagext.Tag; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; public class SimpleTagHandler3 extends TagSupport { private Tag parent; public int doStartTag() { JspWriter out = pageContext.getOut(); try { out.print("<br>Empty tag example"); } catch (Exception e) { System.out.println(e); } return EVAL_BODY_INCLUDE; } public int doEndTag() { return EVAL_PAGE; } }
simpleTag3.tld
<taglib> <tlib-version>1.0</tlib-version> <jsp-version>2.0</jsp-version> <tag> <name>mytag3</name> <tag-class>pack.SimpleTagHandler3</tag-class> </tag> </taglib>
customTagEmptyExample.jsp
<%@taglib uri="/WEB-INF/simpleTag3.tld" prefix="dev" %> <html> <head> <title>Empty Custom tag Example</title> <body> <b>Body of JSP page</b> <br><b>doStartTag()........</b> <dev:mytag3></dev:mytag3> <br><b>doEndTag()</b> </body> </head> </html>
Output :
When you will execute the jsp page you will get the output as :
[ 0 ] Comments