{"id":10471,"date":"2015-08-28T00:14:51","date_gmt":"2015-08-28T04:14:51","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10471"},"modified":"2015-08-24T10:29:18","modified_gmt":"2015-08-24T14:29:18","slug":"repeattag-java-custom-tag-that-repeats-the-tag-body-a-specified-number-of-times","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10471","title":{"rendered":"RepeatTag.java Custom tag that repeats the tag body a specified number of times"},"content":{"rendered":"<pre>RepeatTag.java Custom tag that repeats the tag body a specified number of times\r\n\r\npackage cwp.tags;\r\n\r\nimport javax.servlet.jsp.*;\r\nimport javax.servlet.jsp.tagext.*;\r\nimport java.io.*;\r\n\r\n\/** A tag that repeats the body the specified\r\n\u00a0*\u00a0 number of times.\r\n\u00a0*\u00a0 &lt;P&gt;\r\n\u00a0*\u00a0 Taken from Core Web Programming Java 2 Edition\r\n\u00a0*\u00a0 from Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 May be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class RepeatTag extends BodyTagSupport {\r\n\u00a0 private int reps;\r\n\r\n\u00a0 public void setReps(String repeats) {\r\n\u00a0\u00a0\u00a0 try {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 reps = Integer.parseInt(repeats);\r\n\u00a0\u00a0\u00a0 } catch(NumberFormatException nfe) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 reps = 1;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n\r\n\u00a0 public int doAfterBody() {\r\n\u00a0\u00a0\u00a0 if (reps-- &gt;= 1) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 BodyContent body = getBodyContent();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 try {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JspWriter out = body.getEnclosingWriter();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 out.println(body.getString());\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 body.clearBody(); \/\/ Clear for next evaluation\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 } catch(IOException ioe) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"Error in RepeatTag: \" + ioe);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 return(EVAL_BODY_TAG);\r\n\u00a0\u00a0\u00a0 } else {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 return(SKIP_BODY);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}\r\n\r\nRepeatExample.jsp\r\n\r\n\r\n&lt;!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"&gt;\r\n&lt;!-- \r\nIllustration of RepeatTag tag. \r\n\r\nTaken from Core Web Programming Java 2 Edition\r\nfrom Prentice Hall and Sun Microsystems Press,\r\n.\r\nMay be freely used or adapted. \r\n--&gt;\r\n&lt;HTML&gt;\r\n&lt;HEAD&gt;\r\n&lt;TITLE&gt;Some 40-Digit Primes&lt;\/TITLE&gt;\r\n&lt;LINK REL=STYLESHEET\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 HREF=\"JSP-Styles.css\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 TYPE=\"text\/css\"&gt;\r\n&lt;\/HEAD&gt;\r\n&lt;BODY&gt;\r\n&lt;H1&gt;Some 40-Digit Primes&lt;\/H1&gt;\r\nEach entry in the following list is the first prime number \r\nhigher than a randomly selected 40-digit number.\r\n&lt;%@ taglib uri=\"cwp-taglib.tld\" prefix=\"cwp\" %&gt;\r\n&lt;OL&gt;\r\n&lt;!-- Repeats N times. A null reps value means repeat once. --&gt;\r\n&lt;cwp:repeat reps='&lt;%= request.getParameter(\"repeats\") %&gt;'&gt;\r\n\u00a0 &lt;LI&gt;&lt;cwp:prime length=\"40\" \/&gt;\r\n&lt;\/cwp:repeat&gt;\r\n&lt;\/OL&gt;\r\n&lt;\/BODY&gt;\r\n&lt;\/HTML&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>RepeatTag.java Custom tag that repeats the tag body a specified number of times package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; \/** A tag that repeats the body the specified \u00a0*\u00a0 number of times. \u00a0*\u00a0 &lt;P&gt; \u00a0*\u00a0 Taken from Core Web Programming Java 2 Edition \u00a0*\u00a0 from Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 . &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10471\">Continue reading<\/a><\/p>\n","protected":false},"author":130,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1417,1424],"tags":[706,308,285],"class_list":["post-10471","post","type-post","status-publish","format-standard","hentry","category-code-programming-samples--","category-javaj2eej2me","tag-code","tag-java","tag-285","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":27127,"url":"http:\/\/bangla.sitestree.com\/?p=27127","url_meta":{"origin":10471,"position":0},"title":"RepeatTag.java Custom tag that repeats the tag body a specified number of times #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 11, 2021","format":false,"excerpt":"RepeatTag.java Custom tag that repeats the tag body a specified number of times package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; \/** A tag that repeats the body the specified * number of times. * <P> * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and\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":26525,"url":"http:\/\/bangla.sitestree.com\/?p=26525","url_meta":{"origin":10471,"position":1},"title":"ShowMessage.java  Servlet that demonstrates the use of initialization parameters. #Programming Code Examples #Java\/J2EE\/J2ME #Servlet","author":"Author-Check- Article-or-Video","date":"April 27, 2021","format":false,"excerpt":"ShowMessage.java Servlet that demonstrates the use of initialization parameters. Remember that, to use this servlet, you have to do three things: * Put the modified web.xml file in the WEB-INF directory. * Restart the server. * Use the registered servlet name (i.e., the URL http:\/\/host\/servlet\/ShowMsg), not the raw servlet name\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":10160,"url":"http:\/\/bangla.sitestree.com\/?p=10160","url_meta":{"origin":10471,"position":2},"title":"ShowMessage.java Servlet that demonstrates the use of initialization parameters.","author":"","date":"August 16, 2015","format":false,"excerpt":"ShowMessage.java\u00a0 Servlet that demonstrates the use of initialization parameters. Remember that, to use this servlet, you have to do three things: \u00a0\u00a0\u00a0 * Put the modified web.xml file in the WEB-INF directory. \u00a0\u00a0\u00a0 * Restart the server. \u00a0\u00a0\u00a0 * Use the registered servlet name (i.e., the URL http:\/\/host\/servlet\/ShowMsg), not the\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":10457,"url":"http:\/\/bangla.sitestree.com\/?p=10457","url_meta":{"origin":10471,"position":3},"title":"HeadingTag.java Custom tag that makes use of a tag body","author":"","date":"August 28, 2015","format":false,"excerpt":"HeadingTag.java Custom tag that makes use of a tag body package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; \/** Generates an HTML heading with the specified background \u00a0*\u00a0 color, foreground color, alignment, font, and font size. \u00a0*\u00a0 You can also turn on a border around it, which normally \u00a0*\u00a0 just\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":10473,"url":"http:\/\/bangla.sitestree.com\/?p=10473","url_meta":{"origin":10471,"position":4},"title":"IfTag.java, IfConditionTag.java, IfThenTag.java, and IfElseTag.java, Custom tags that make use of tag nesting","author":"","date":"August 28, 2015","format":false,"excerpt":"IfTag.java, IfConditionTag.java, IfThenTag.java, and IfElseTag.java, Custom tags that make use of tag nesting IfTag.java package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import javax.servlet.*; \/** A tag that acts like an if\/then\/else. \u00a0*\u00a0 <P> \u00a0*\u00a0 Taken from Core Web Programming Java 2 Edition \u00a0*\u00a0 from Prentice Hall and Sun Microsystems\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":27115,"url":"http:\/\/bangla.sitestree.com\/?p=27115","url_meta":{"origin":10471,"position":5},"title":"HeadingTag.java Custom tag that makes use of a tag body #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 11, 2021","format":false,"excerpt":"HeadingTag.java Custom tag that makes use of a tag body package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; \/** Generates an HTML heading with the specified background * color, foreground color, alignment, font, and font size. * You can also turn on a border around it, which normally * just\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\/10471","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\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10471"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10471\/revisions"}],"predecessor-version":[{"id":10472,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10471\/revisions\/10472"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10471"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}