{"id":10434,"date":"2015-08-28T07:22:21","date_gmt":"2015-08-28T11:22:21","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10434"},"modified":"2015-08-24T10:25:43","modified_gmt":"2015-08-24T14:25:43","slug":"saleentry2-jsp-page-that-uses-the-saleentry-bean-using-the-param-attribute-to-read-request-parameters-and-assign-them-to-bean-properties","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10434","title":{"rendered":"SaleEntry2.jsp Page that uses the SaleEntry bean, using the param attribute to read request parameters and assign them to bean properties"},"content":{"rendered":"<p>SaleEntry2.jsp Page that uses the SaleEntry bean, using the param attribute to read request parameters and assign them to bean properties<\/p>\n<pre>&lt;!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"&gt;\r\n&lt;!-- \r\nExample of using jsp:setProperty and an explicity association\r\nwith an input parameter. See SaleEntry1.jsp\r\nand SaleEntry3.jsp for alternatives. \r\n\u00a0 \u00a0\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;Using jsp:setProperty&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\r\n&lt;BODY&gt;\r\n&lt;TABLE BORDER=5 ALIGN=\"CENTER\"&gt;\r\n\u00a0 &lt;TR&gt;&lt;TH CLASS=\"TITLE\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Using jsp:setProperty&lt;\/TABLE&gt;\r\n&lt;jsp:useBean id=\"entry\" class=\"cwp.SaleEntry\" \/&gt;\r\n&lt;jsp:setProperty \r\n\u00a0\u00a0\u00a0 name=\"entry\"\r\n\u00a0\u00a0\u00a0 property=\"itemID\"\r\n\u00a0\u00a0\u00a0 param=\"itemID\" \/&gt;\r\n&lt;jsp:setProperty \r\n\u00a0\u00a0\u00a0 name=\"entry\"\r\n\u00a0\u00a0\u00a0 property=\"numItems\"\r\n\u00a0\u00a0\u00a0 param=\"numItems\" \/&gt;\r\n&lt;%-- WARNING! Both the JSWDK 1.0.1 and the Java Web Server\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 have a bug that makes them fail on double\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type conversions of the following sort.\r\n--%&gt;\r\n&lt;jsp:setProperty \r\n\u00a0\u00a0\u00a0 name=\"entry\"\r\n\u00a0\u00a0\u00a0 property=\"discountCode\"\r\n\u00a0\u00a0\u00a0 param=\"discountCode\" \/&gt;\r\n&lt;BR&gt;\r\n&lt;TABLE ALIGN=\"CENTER\" BORDER=1&gt;\r\n&lt;TR CLASS=\"COLORED\"&gt;\r\n\u00a0 &lt;TH&gt;Item ID&lt;TH&gt;Unit Price&lt;TH&gt;Number Ordered&lt;TH&gt;Total Price\r\n&lt;TR ALIGN=\"RIGHT\"&gt;\r\n\u00a0 &lt;TD&gt;&lt;jsp:getProperty name=\"entry\" property=\"itemID\" \/&gt;\r\n\u00a0 &lt;TD&gt;$&lt;jsp:getProperty name=\"entry\" property=\"itemCost\" \/&gt;\r\n\u00a0 &lt;TD&gt;&lt;jsp:getProperty name=\"entry\" property=\"numItems\" \/&gt;\r\n\u00a0 &lt;TD&gt;$&lt;jsp:getProperty name=\"entry\" property=\"totalCost\" \/&gt;\r\n&lt;\/TABLE&gt;\u00a0\u00a0\u00a0 \u00a0\r\n&lt;\/BODY&gt;\r\n&lt;\/HTML&gt;\r\n\r\n\r\nSaleEntry.java \/\/SaleEntry Bean\r\n\r\npackage 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>SaleEntry2.jsp Page that uses the SaleEntry bean, using the param attribute to read request parameters and assign them to bean properties &lt;!DOCTYPE HTML PUBLIC &#8220;-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN&#8221;&gt; &lt;!&#8211; Example of using jsp:setProperty and an explicity association with an input parameter. See SaleEntry1.jsp and SaleEntry3.jsp for alternatives. \u00a0 \u00a0 Taken from Core Web Programming Java &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10434\">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-10434","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":27082,"url":"http:\/\/bangla.sitestree.com\/?p=27082","url_meta":{"origin":10434,"position":0},"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":[]},{"id":10432,"url":"http:\/\/bangla.sitestree.com\/?p=10432","url_meta":{"origin":10434,"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":10436,"url":"http:\/\/bangla.sitestree.com\/?p=10436","url_meta":{"origin":10434,"position":2},"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":27080,"url":"http:\/\/bangla.sitestree.com\/?p=27080","url_meta":{"origin":10434,"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":27084,"url":"http:\/\/bangla.sitestree.com\/?p=27084","url_meta":{"origin":10434,"position":4},"title":"SaleEntry3.jsp Page that uses the SaleEntry bean, using property=&quot;*&quot; 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":"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. Taken from Core Web Programming\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":10434,"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\/10434","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=10434"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10434\/revisions"}],"predecessor-version":[{"id":10435,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10434\/revisions\/10435"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10434"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}