{"id":23184,"date":"2021-03-26T20:15:32","date_gmt":"2021-03-27T00:15:32","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/creating-custom-tags-in-jsp-root-by-sayed-ahmed\/"},"modified":"2021-03-26T20:15:32","modified_gmt":"2021-03-27T00:15:32","slug":"creating-custom-tags-in-jsp-root-by-sayed-ahmed","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=23184","title":{"rendered":"Creating Custom Tags in JSP #Root #By Sayed Ahmed"},"content":{"rendered":"<p>By Sayed, January 13th, 2008 [use large font in IE\/Firefox]<\/p>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<pre>How to create custom tags in JSP?\r\nYou can create custom tags in JSP. \r\nSteps:\r\n-----\r\n1. You have to create a Java file that will define the operation of the custom tag\r\n2. For the Java file, you have to extend javax.servlet.jsp.tagext.BodyTagSupport class\r\n3. in your implementation, you have to override (re-write) doStartTag(), doEndTag(), \r\nand doAfterBody() methods\r\n4. Create tag library description file(XML file with .tld extension).\r\n\r\nExample\r\n-------\r\n\r\nImplement a tag that reverses a string\r\n\r\n\r\nimport java.io.IOException;\r\nimport javax.servlet.jsp.JspTagException;\r\nimport javax.servlet.jsp.JspWriter;\r\nimport javax.servlet.jsp.tagext.BodyContent;\r\nimport javax.servlet.jsp.tagext.BodyTagSupport;\r\n\r\npublic class ReverseTag extends BodyTagSupport \r\n{\r\n    private static final long serialVersionUID = 1L;    \r\n    \r\n    \/\/override doStartTag\r\n    public int doStartTag() throws JspTagException{\r\n        return EVAL_BODY_TAG;\r\n    }    \r\n    \r\n    \/\/override doEndTag\r\n    public int doEndTag() throws JspTagException \r\n    {\r\n      try {\r\n           JspWriter out = pageContext.getOut();\r\n      } catch (Exception ex) {\r\n           throw new JspTagException(\"Exception\" + ex);\r\n      }\r\n    return SKIP_BODY;\r\n }\r\n\r\n\/\/reverse the text    \r\npublic int doAfterBody() throws JspTagException \r\n{\r\n    BodyContent body = getBodyContent();\r\n    try {\r\n            JspWriter out = body.getEnclosingWriter();\r\n            \/\/get text inside the tag\r\n            String bodyContent = body.getString();\r\n            \/\/reverse the text\r\n            if (bodyContent != null) {\r\n                for (int i = bodyContent.length() - 1; i &gt;= 0; i--) {\r\n                    out.print(bodyContent.charAt(i));\r\n                }\r\n            }\r\n            out.println();\r\n            body.clearBody(); \/\/ Clear for next evaluation\r\n          } catch (IOException ioe) {\r\n               throw new JspTagException(\"Exception at doAfterBody \" + ioe);\r\n     }\r\n        return (SKIP_BODY);\r\n    }\r\n}\r\n\r\n5. Create the taglib descriptor\r\n\r\n&lt;?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?&gt;\r\n&lt;!DOCTYPE taglib PUBLIC \"-\/\/Sun Microsystems, Inc.\r\n\/\/DTD JSP Tag Library 1.1\/\/EN\" \"http:\/\/java.sun.com\/j2ee\/dtds\/web-jsptaglibrary_1_1.dtd\"&gt;\r\n&lt;taglib&gt;\r\n    &lt;tlibversion&gt;1.0&lt;\/tlibversion&gt;\r\n    &lt;jspversion&gt;1.1&lt;\/jspversion&gt;\r\n    &lt;shortname&gt;&lt;\/shortname&gt;\r\n    &lt;info&gt;&lt;\/info&gt;\r\n    &lt;tag&gt;\r\n        &lt;name&gt;stringreverse&lt;\/name&gt;\r\n        &lt;tagclass&gt;net.justetc.taglibrary.ReverseTag&lt;\/tagclass&gt;\r\n        &lt;info&gt;\r\n            Reverse the text\r\n        &lt;\/info&gt;\r\n    &lt;\/tag&gt;\r\n&lt;\/taglib&gt;\r\n\r\n\r\n6. Example use of the custom tag\r\n\r\n\r\n&lt;%@ taglib uri=\"\/WEB-INF\/reverse.tld\" prefix=\"reverse\" %&gt;\r\n\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;title&gt;Custom Tag library&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body bgcolor=\"#ffffff\"&gt;\r\n\r\n&lt;hr \/&gt;\r\n&lt;reverse:stringreverse&gt;\r\n        justetc\r\n&lt;\/reverse:stringreverse&gt;\r\n&lt;hr \/&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n\r\n<\/pre>\n<p> From: http:\/\/sitestree.com\/?p=3645<br \/> Categories:Root, By Sayed Ahmed<br \/>Tags:<br \/> Post Data:2016-09-15 14:21:09<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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: &#8212;&#8211; 1. You have to create a Java file that will define the operation of the custom tag 2. For the Java file, you have to extend javax.servlet.jsp.tagext.BodyTagSupport class 3. &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=23184\">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-23184","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":69276,"url":"http:\/\/bangla.sitestree.com\/?p=69276","url_meta":{"origin":23184,"position":0},"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":[]},{"id":10442,"url":"http:\/\/bangla.sitestree.com\/?p=10442","url_meta":{"origin":23184,"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":10446,"url":"http:\/\/bangla.sitestree.com\/?p=10446","url_meta":{"origin":23184,"position":2},"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":27090,"url":"http:\/\/bangla.sitestree.com\/?p=27090","url_meta":{"origin":23184,"position":3},"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":27094,"url":"http:\/\/bangla.sitestree.com\/?p=27094","url_meta":{"origin":23184,"position":4},"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":69282,"url":"http:\/\/bangla.sitestree.com\/?p=69282","url_meta":{"origin":23184,"position":5},"title":"JSP: Random Information #37","author":"Author-Check- Article-or-Video","date":"August 16, 2021","format":false,"excerpt":"Three JSP constructs: scripting elements, actions, directives Scripting elements: expressions, scriptlets, declarations Expression = translates to println in servlets in _jspService methods < % = expression %> < % = new java.util.Date() %> inserts values directly to the output scriptlet: block of java code : directly inserted into the related\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\/23184","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=23184"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/23184\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23184"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}