{"id":69284,"date":"2021-08-16T20:38:54","date_gmt":"2021-08-17T00:38:54","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/jsp-custom-tags-37\/"},"modified":"2021-08-16T20:38:54","modified_gmt":"2021-08-17T00:38:54","slug":"jsp-custom-tags-37","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=69284","title":{"rendered":"JSP: Custom Tags #37"},"content":{"rendered":"<ul>\n<li> Custom Tags = alternatives to java beans for JSP = reduces some limitations of JavaBeans (in JSP) like to few methods to access the bean, you may still require to write much java code in JSP [that we want to avoid]<\/li>\n<li> <b>Overview:<\/b><\/li>\n<li> Custom tag with no body should extend TagSupport class that implements Tag interface<\/li>\n<li> Tags extending TagSupport should extend only one method &#8211; doStartTag(), and in this case the doStartTag() method should return SKIP_BODY<\/li>\n<li> A simple tag code is shown below:<br \/><img src='images\/842.jpg' \/><\/li>\n<li>Next you need to define a tld file &#8211; a descriptor file for the tag &#8211; XML file.<\/li>\n<li> In the tld files, the most important tag is the <b>tag<\/b><\/li>\n<li> The sub-elements of the tag element are: name, tag-class, description, body-content.<\/li>\n<li> Sample:\n<pre>  SimpleTag  tags.SimpleTag  Sample TLD File  empty<\/pre>\n<\/li>\n<li> To use the custom tag in a JSP file, You need to provide a directive like:\n<pre> <\/pre>\n<\/li>\n<li>Example use: <\/li>\n<li> How to add attributes to tags: In the class, declare private variable for each attribute you want, define a setXXX method for each of the attribute<\/li>\n<li> In the tld &#8211; file, add an attribute tag for each attribute you want. This attribute tag can have following sub-elements: name, required, rtexprvalue = can the value be an expression, type=class to which the value should typecast to, description <\/li>\n<li> Defining tag body: doStartTag() should return EVAL_VALUE_INCLUDE<\/li>\n<li> A new method named doEndTag() should be defined that will define what will be the effect on the body text. <\/li>\n<li> The doEndTag() method may return EVAL_PAGE = continue to process rest of the JSP page, SKIP_PAGE = stop processing rest of the page <\/li>\n<li> To support body inside the custom tags &#8211; body-content tag in the tld file needs to be adjusted: example \n<pre>  SimpleTag  tags.SimpleTag  Sample TLD File  JSP<\/pre>\n<\/li>\n<li>Example use:  Body Text  <\/li>\n<\/ul>\n<p>From: http:\/\/sitestree.com\/?p=4964<br \/> Categories:37<br \/>Tags:<br \/> Post Data:2012-12-20 05:06:38<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Custom Tags = alternatives to java beans for JSP = reduces some limitations of JavaBeans (in JSP) like to few methods to access the bean, you may still require to write much java code in JSP [that we want to avoid] Overview: Custom tag with no body should extend TagSupport class that implements Tag interface &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=69284\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-69284","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10446,"url":"http:\/\/bangla.sitestree.com\/?p=10446","url_meta":{"origin":69284,"position":0},"title":"SimpleExample.jsp Page that uses the ExampleTag custom tag.","author":"","date":"August 28, 2015","format":false,"excerpt":"SimpleExample.jsp Page that uses the ExampleTag custom tag. <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Illustration of very simple JSP custom tag. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. --> <HTML> <HEAD> <%@ taglib\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10442,"url":"http:\/\/bangla.sitestree.com\/?p=10442","url_meta":{"origin":69284,"position":1},"title":"ExampleTag.java Very simple custom tag. Remember to install it in the WEB-INF\/classes\/cwp\/tags directory.","author":"","date":"August 28, 2015","format":false,"excerpt":"ExampleTag.java Very simple custom tag. Remember to install it in the WEB-INF\/classes\/cwp\/tags directory. package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; \/** Very simple JSP tag that just inserts a string \u00a0*\u00a0 (\"Custom tag example...\") into the output. \u00a0*\u00a0 The actual name of the tag is not defined here; \u00a0*\u00a0\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27094,"url":"http:\/\/bangla.sitestree.com\/?p=27094","url_meta":{"origin":69284,"position":2},"title":"SimpleExample.jsp Page that uses the ExampleTag custom tag. #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 10, 2021","format":false,"excerpt":"SimpleExample.jsp Page that uses the ExampleTag custom tag. <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Illustration of very simple JSP custom tag. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. --> <HTML> <HEAD> <%@ taglib\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":23184,"url":"http:\/\/bangla.sitestree.com\/?p=23184","url_meta":{"origin":69284,"position":3},"title":"Creating Custom Tags in JSP #Root #By Sayed Ahmed","author":"Author-Check- Article-or-Video","date":"March 26, 2021","format":false,"excerpt":"By Sayed, January 13th, 2008 [use large font in IE\/Firefox] How to create custom tags in JSP? You can create custom tags in JSP. Steps: ----- 1. You have to create a Java file that will define the operation of the custom tag 2. For the Java file, you have\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27090,"url":"http:\/\/bangla.sitestree.com\/?p=27090","url_meta":{"origin":69284,"position":4},"title":"ExampleTag.java Very simple custom tag. Remember to install it in the WEB-INF\/classes\/cwp\/tags directory. #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 10, 2021","format":false,"excerpt":"ExampleTag.java Very simple custom tag. Remember to install it in the WEB-INF\/classes\/cwp\/tags directory. package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; \/** Very simple JSP tag that just inserts a string * (\"Custom tag example...\") into the output. * The actual name of the tag is not defined here; *\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":69276,"url":"http:\/\/bangla.sitestree.com\/?p=69276","url_meta":{"origin":69284,"position":5},"title":"Creating Custom Tags in JSP #37","author":"Author-Check- Article-or-Video","date":"August 16, 2021","format":false,"excerpt":"How to create custom tags in JSP?You can create custom tags in JSP. Steps:-----1. You have to create a Java file that will define the operation of the custom tag2. For the Java file, you have to extend javax.servlet.jsp.tagext.BodyTagSupport class3. in your implementation, you have to override (re-write) doStartTag(), doEndTag(),\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69284"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69284\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69284"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}