{"id":10429,"date":"2015-08-28T07:18:44","date_gmt":"2015-08-28T11:18:44","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10429"},"modified":"2015-08-24T10:06:36","modified_gmt":"2015-08-24T14:06:36","slug":"saleentry-java-bean-used-to-demonstrate-the-various-approaches-to-reading-request-parameters-and-stuffing-them-into-java-objects","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10429","title":{"rendered":"SaleEntry.java Bean used to demonstrate the various approaches to reading request parameters and stuffing them into Java objects."},"content":{"rendered":"<pre>package cwp;\r\n\r\n\/** Simple bean to illustrate the various forms\r\n\u00a0*\u00a0 of jsp:setProperty.\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 SaleEntry {\r\n\u00a0 private String itemID = \"unknown\";\r\n\u00a0 private double discountCode = 1.0;\r\n\u00a0 private int numItems = 0;\r\n\r\n\u00a0 public String getItemID() {\r\n\u00a0\u00a0\u00a0 return(itemID);\r\n\u00a0 }\r\n\r\n\u00a0 public void setItemID(String itemID) {\r\n\u00a0\u00a0\u00a0 if (itemID != null) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 this.itemID = itemID;\r\n\u00a0\u00a0\u00a0 } else {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 this.itemID = \"unknown\";\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n\r\n\u00a0 public double getDiscountCode() {\r\n\u00a0\u00a0\u00a0 return(discountCode);\r\n\u00a0 }\r\n\r\n\u00a0 public void setDiscountCode(double discountCode) {\r\n\u00a0\u00a0\u00a0 this.discountCode = discountCode;\r\n\u00a0 }\r\n\r\n\u00a0 public int getNumItems() {\r\n\u00a0\u00a0\u00a0 return(numItems);\r\n\u00a0 }\r\n\r\n\u00a0 public void setNumItems(int numItems) {\r\n\u00a0\u00a0\u00a0 this.numItems = numItems;\r\n\u00a0 }\r\n\r\n\u00a0 \/\/ In real life, replace this with database lookup.\r\n\r\n\u00a0 public double getItemCost() {\r\n\u00a0\u00a0\u00a0 double cost;\r\n\u00a0\u00a0\u00a0 if (itemID.equals(\"a1234\")) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 cost = 12.99*getDiscountCode();\r\n\u00a0\u00a0\u00a0 } else {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 cost = -9999;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 return(roundToPennies(cost));\r\n\u00a0 }\r\n\r\n\u00a0 private double roundToPennies(double cost) {\r\n\u00a0\u00a0\u00a0 return(Math.floor(cost*100)\/100.0);\r\n\u00a0 }\r\n\r\n\u00a0 public double getTotalCost() {\r\n\u00a0\u00a0\u00a0 return(getItemCost() * getNumItems());\r\n\u00a0 }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>package cwp; \/** Simple bean to illustrate the various forms \u00a0*\u00a0 of jsp:setProperty. \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 . \u00a0*\u00a0 May be freely used or adapted. \u00a0*\/ public class SaleEntry { \u00a0 private String itemID = &#8220;unknown&#8221;; \u00a0 private double &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10429\">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-10429","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":27078,"url":"http:\/\/bangla.sitestree.com\/?p=27078","url_meta":{"origin":10429,"position":0},"title":"SaleEntry.java Bean used to demonstrate the various approaches to reading request parameters and stuffing them into Java objects. #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 10, 2021","format":false,"excerpt":"package cwp; \/** Simple bean to illustrate the various forms * of jsp:setProperty. * <P> * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * May be freely used or adapted. *\/ public class SaleEntry { private String itemID =\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":10432,"url":"http:\/\/bangla.sitestree.com\/?p=10432","url_meta":{"origin":10429,"position":1},"title":"SaleEntry1.jsp Page that uses the SaleEntry bean, using explicit Java code to read request parameters and assign them to bean properties.","author":"","date":"August 28, 2015","format":false,"excerpt":"SaleEntry1.jsp Page that uses the SaleEntry bean, using explicit Java code to read request parameters and assign them to bean properties. \u00a0 <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Example of using jsp:setProperty with an explicit value supplied to the \"value\" attribute. See SaleEntry2.jsp and SaleEntry3.jsp for alternatives. Taken\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":10434,"url":"http:\/\/bangla.sitestree.com\/?p=10434","url_meta":{"origin":10429,"position":2},"title":"SaleEntry2.jsp Page that uses the SaleEntry bean, using the param attribute to read request parameters and assign them to bean properties","author":"","date":"August 28, 2015","format":false,"excerpt":"SaleEntry2.jsp Page that uses the SaleEntry bean, using the param attribute to read request parameters and assign them to bean properties <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Example of using jsp:setProperty and an explicity association with an input parameter. See SaleEntry1.jsp and SaleEntry3.jsp for alternatives. \u00a0 \u00a0 Taken\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":27080,"url":"http:\/\/bangla.sitestree.com\/?p=27080","url_meta":{"origin":10429,"position":3},"title":"SaleEntry1.jsp Page that uses the SaleEntry bean, using explicit Java code to read request parameters and assign them to bean properties. #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 10, 2021","format":false,"excerpt":"SaleEntry1.jsp Page that uses the SaleEntry bean, using explicit Java code to read request parameters and assign them to bean properties. <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Example of using jsp:setProperty with an explicit value supplied to the \"value\" attribute. See SaleEntry2.jsp and SaleEntry3.jsp for alternatives. Taken from\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":10436,"url":"http:\/\/bangla.sitestree.com\/?p=10436","url_meta":{"origin":10429,"position":4},"title":"SaleEntry3.jsp Page that uses the SaleEntry bean, using property=&#8221;*&#8221; to read request parameters and assign them to bean properties","author":"","date":"August 28, 2015","format":false,"excerpt":"SaleEntry3.jsp Page that uses the SaleEntry bean, using property=\"*\" to read request parameters and assign them to bean properties <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Example of using jsp:setProperty and a general association with the input parameters. See SaleEntry1.jsp and SaleEntry2.jsp for alternatives. \u00a0 \u00a0 Taken from Core\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":27082,"url":"http:\/\/bangla.sitestree.com\/?p=27082","url_meta":{"origin":10429,"position":5},"title":"SaleEntry2.jsp Page that uses the SaleEntry bean, using the param attribute to read request parameters and assign them to bean properties #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 10, 2021","format":false,"excerpt":"SaleEntry2.jsp Page that uses the SaleEntry bean, using the param attribute to read request parameters and assign them to bean properties <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Example of using jsp:setProperty and an explicity association with an input parameter. See SaleEntry1.jsp and SaleEntry3.jsp for alternatives. Taken from Core\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\/10429","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=10429"}],"version-history":[{"count":2,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10429\/revisions"}],"predecessor-version":[{"id":10431,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10429\/revisions\/10431"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10429"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}