JAVA BEANS
JavaBeans can be understood as java classes that can be easily reused and composed
together into an application. Any java class that follows certain design
conventions can be used as a javaBean component. JSP directly supports javaBean components using JSP elements. One can easily create and initialize the
value of the Beans and set their properties.
· useBean: A JSP action element
<jsp:useBean> initiates a JavaBean object into the JSP page.
Syntax:
<jsp:useBean id=”object_name”
class=”class_name” scope=”page|request|session|application” | />
· setProperty: The <jsp:setProperty> action
tag assigns a new value to the specified property of the specified bean object.
Syntax:
<jsp:setProperty name=”obj_name”
property=”prop_name” value=”prop_value”/>
· getProperty: The <jsp:getProperty> action
element retrieves the value of the specified property of the specified bean
object. The value is converted to a string.
Syntax:
<jsp:getProperty name=”obj_name”
property=”prop_name” />
EXAMPLES:
1. <jsp:useBean
id="calendar"
scope="page"
class="employee.calendar"
/>
<h1>
<jsp:getProperty
name="calendar"
property="user_name"
/>
</h1>
2. <jsp:useBean
id="firstBean"
scope="session"
class="packedBeans.messageBeans"
/>
<jsp:setProperty
property="message"
value="Message
for IMCA V"
/>
<a
href="bitmesra.ac.in">
<jsp:getProperty
name="firstBean"
property="message"
/>
</a>
Comments