आपकी ऑफलाइन सहायता

BACK
49

सी प्रोग्रामिंग

149

पाइथन प्रोग्रामिंग

49

सी प्लस प्लस

99

जावा प्रोग्रामिंग

149

जावास्क्रिप्ट

49

एंगुलर जे.एस.

69

पी.एच.पी.
माय एस.क्यू.एल.

99

एस.क्यू.एल.

Free

एच.टी.एम.एल.

99

सी.एस.एस.

149

आर प्रोग्रामिंग

39

जे.एस.पी.





डाउनलोड पी.डी.एफ. ई-बुक्स
JSP - useBean, setProperty and getProperty action tag

JavaBeans ये classes होते है | इन classes का इस्तेमाल dynamic webpages में भी किया जाता है | इन classes का इस्तेमाल एक से ज्यादा JSP Pages पर किया जा सकता है |


Syntax for useBean Action tag in JSP

<jsp: useBean id="myID" class="package_name.class_name" />

Attributes for useBean Action tag in JSP

id : यहाँ पर useBean के लिए unique name; identify किया जाता है |

class : यहाँ पर package name के साथ उसका class name भी दिया जाता है | इस class पर कोई argument नहीं चाहिए, इसके लिए कोई constructor नहीं चाहिए और ये abstract नहीं होना चाहिए |


<jsp:setProperty> Action Tag

JavaBean के लिए property को set किया जाता है | property set करने के लिए Bean को पहले से defined होना जरुरी होता है |

Syntax for setProperty Action tag in JSP

<jsp:useBean id = "myID" class="package_name.class_name"/>
...
<jsp:setProperty name = "myID" property = "property_name" value="some_value"/>
OR
<jsp:useBean id = "myID" class="package_name.class_name">
...
<jsp:setProperty name = "myID" property = "property_name" value="some_value"/>
</jsp:useBean>

<jsp:getProperty> Action Tag

set किये हुए property को access करने के लिए getProperty इस action tag का इस्तेमाल किया जाता है |

Syntax for getProperty Action tag in JSP

<jsp:useBean id = "myID" class="package_name.class_name"/>
...
<jsp:getProperty name = "myID" property = "property_name" />
OR
<jsp:useBean id = "myID" class="package_name.class_name">
...
<jsp:getProperty name = "myID" property = "property_name" />
</jsp:useBean>

Example for useBean Action tag in JSP

Employee.java
package hindilearn.in;

public class Employee{
    private String name;
	private float salary;
        
        public String getname() {
		return name;
	}
	public void setname(String name) {
		this.name = name;
	}
	public float getSalary() {
		return salary;
	}
	public void setSalary(float salary) {
		this.salary = salary;
	}
}

Sample.jsp
<html>
<body>

<jsp:useBean id='emp'  class='hindilearn.in.Person'>
   <jsp:setProperty name='emp' property='name'
                    value='Rakesh Yadav'/>
   <jsp:setProperty name='emp' property='salary'
                    value='100000.50'/>
</jsp:useBean>

<p><b>Employee Name :</b>
   <jsp:getProperty name='emp' property='name'/>
</p>
<p><b>Employee Salary :</b>
   <jsp:getProperty name='emp' property='salary'/>
</p>
</body>
</html>
Output :
Employee Name : Rakesh Yadav

Employee Salary : 100000.5