{"id":300,"date":"2013-09-06T09:20:06","date_gmt":"2013-09-06T09:20:06","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=300"},"modified":"2013-09-06T09:24:14","modified_gmt":"2013-09-06T09:24:14","slug":"defining-a-simple-custom-tag-tld","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/defining-a-simple-custom-tag-tld\/","title":{"rendered":"Defining a Simple Custom Tag TLD"},"content":{"rendered":"<p><strong>CustomTags.java<\/strong><br \/>\nThis is the File which defines the Property of the Tag<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage com.mugil.custTags;\r\n\r\nimport java.io.IOException;\r\nimport javax.servlet.jsp.JspException;\r\nimport javax.servlet.jsp.tagext.TagSupport;\r\n\r\npublic class CustomTags extends TagSupport  \r\n{\r\n  private static final long serialVersionUID = 1L;\r\n\t\r\n  public int doStartTag() throws JspException \r\n  {\t\t\r\n     StringBuffer SamBuffer = new StringBuffer();\r\n     SamBuffer.append(&quot;Sample Message&quot;);\r\n\t\t\r\n     try\r\n     {\r\n\tpageContext.getOut().write(SamBuffer.toString());\r\n     }\r\n     catch (IOException e)\r\n     {\r\n\te.printStackTrace();\r\n     }\r\n\t\t\r\n  \treturn EVAL_PAGE;\r\n   }\r\n\t\r\n   public int doEndTag() throws JspException \r\n   {\r\n      return EVAL_PAGE;\r\n   }\r\n}\r\n<\/pre>\n<p><strong>DisplayName.tld<\/strong><br \/>\nThis xml file creates the Relation between the tag and the property of the tag as defined in the java file.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n&lt;taglib&gt;\r\n  &lt;tlib-version&gt;1.0&lt;\/tlib-version&gt;\r\n  &lt;jsp-version&gt;2.0&lt;\/jsp-version&gt;\r\n  &lt;shortname&gt;Example TLD&lt;\/shortname&gt;\r\n  &lt;tag&gt;\r\n    &lt;name&gt;Hello&lt;\/name&gt;\r\n    &lt;tagclass&gt;com.mugil.custTags.CustomTags&lt;\/tagclass&gt;\r\n    &lt;bodycontent&gt;empty&lt;\/bodycontent&gt;\r\n  &lt;\/tag&gt;\r\n&lt;\/taglib&gt;\r\n<\/pre>\n<p><strong>Sample.jsp <\/strong><br \/>\nJSP File in which the custom tag is Used.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;%@taglib prefix=&quot;DisplayName&quot; uri=&quot;\/WEB-INF\/tld\/DisplayName.tld&quot;%&gt;\r\n.\r\n.\r\n.\r\n.\r\n&lt;body&gt;\r\n &lt;h1&gt;\r\n    &lt;DisplayName:Hello\/&gt;\r\n &lt;\/h1&gt;\r\n&lt;\/body&gt;\r\n.\r\n.\r\n.\r\n<\/pre>\n<p><strong>web.xml<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n  &lt;web-app version=&quot;3.0&quot;&gt;\r\n   &lt;servlet&gt;\r\n     &lt;servlet-name&gt;TestServlet&lt;\/servlet-name&gt;\r\n     &lt;servlet-class&gt;com.mugil.custTags.TestServlet&lt;\/servlet-class&gt;\r\n   &lt;\/servlet&gt;\r\n   &lt;servlet-mapping&gt;\r\n     &lt;servlet-name&gt;TestServlet&lt;\/servlet-name&gt;\r\n     &lt;url-pattern&gt;\/TestServlet\/&lt;\/url-pattern&gt;\r\n   &lt;\/servlet-mapping&gt;\r\n  &lt;\/web-app&gt;\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2013\/09\/SampleMsg.png\" alt=\"OP\" height=\"217\"\/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CustomTags.java This is the File which defines the Property of the Tag package com.mugil.custTags; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport; public class CustomTags extends TagSupport { private static final long serialVersionUID = 1L; public int doStartTag() throws JspException { StringBuffer SamBuffer = new StringBuffer(); SamBuffer.append(&quot;Sample Message&quot;); try { pageContext.getOut().write(SamBuffer.toString()); } catch (IOException e) { e.printStackTrace();&hellip; <a href=\"https:\/\/codethataint.com\/blog\/defining-a-simple-custom-tag-tld\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-jstl"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":305,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/300\/revisions\/305"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}