{"id":1688,"date":"2016-09-22T03:55:37","date_gmt":"2016-09-22T03:55:37","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1688"},"modified":"2016-09-22T03:56:47","modified_gmt":"2016-09-22T03:56:47","slug":"using-bean-tag-in-jsp","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/using-bean-tag-in-jsp\/","title":{"rendered":"Using bean Tag in JSP"},"content":{"rendered":"<p><strong><jsp:usebean>tag <\/strong><br \/>\nThe useBean action declares a JavaBean for use in a JSP. Once declared, the bean becomes a scripting variable that can be accessed by both scripting elements and other custom tags used in the JSP.<\/p>\n<p><strong>JSP Syntax<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n&lt;jsp:useBean\r\n        id=&quot;beanInstName&quot;\r\n        scope=&quot;page | request | session | application&quot;       \r\n        class=&quot;package.class&quot;    \r\n        type=&quot;package.class&quot;\r\n&lt;\/jsp:useBean&gt;\r\n<\/pre>\n<p><strong>Example<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n  &lt;jsp:useBean id=&quot;stock&quot; scope=&quot;request&quot; class=&quot;market.Stock&quot; \/&gt;\r\n<\/pre>\n<p><strong>Accessing Values<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n&lt;jsp:useBean id=&quot;date&quot; class=&quot;java.util.Date&quot; \/&gt; \r\n&lt;p&gt;The date\/time is &lt;%= date %&gt;\r\n<\/pre>\n<p><strong>Using getPropertyName() and setPropertyName()<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n&lt;jsp:useBean id=&quot;students&quot; \r\n                    class=&quot;com.tutorialspoint.StudentsBean&quot;&gt; \r\n   &lt;jsp:setProperty name=&quot;students&quot; property=&quot;firstName&quot;\r\n                    value=&quot;Zara&quot;\/&gt;   \r\n&lt;\/jsp:useBean&gt;\r\n\r\n&lt;p&gt;Student First Name: \r\n   &lt;jsp:getProperty name=&quot;students&quot; property=&quot;firstName&quot;\/&gt;\r\n&lt;\/p&gt;\r\n<\/pre>\n<p><strong>Setting Request Scope<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nPersonBean myBean = (PersonBean)request.getAttribute(&quot;myBean&quot;);\r\n\r\nif(myBean == null)\r\n{\r\n   myBean = new PersonBean();\r\n   request.setAttribute(&quot;myBean&quot;, myBean);\r\n}\r\n<\/pre>\n<p><strong>Accessing in JSP<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n&lt;jsp:useBean id=&quot;myBean&quot; class=&quot;PersonBean&quot; scope=&quot;request&quot; \/&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>tag The useBean action declares a JavaBean for use in a JSP. Once declared, the bean becomes a scripting variable that can be accessed by both scripting elements and other custom tags used in the JSP. JSP Syntax &lt;jsp:useBean id=&quot;beanInstName&quot; scope=&quot;page | request | session | application&quot; class=&quot;package.class&quot; type=&quot;package.class&quot; &lt;\/jsp:useBean&gt; Example &lt;jsp:useBean id=&quot;stock&quot; scope=&quot;request&quot; class=&quot;market.Stock&quot;&hellip; <a href=\"https:\/\/codethataint.com\/blog\/using-bean-tag-in-jsp\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"class_list":["post-1688","post","type-post","status-publish","format-standard","hentry","category-jsp"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1688"}],"version-history":[{"count":3,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1688\/revisions"}],"predecessor-version":[{"id":1691,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1688\/revisions\/1691"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}