0% found this document useful (0 votes)
69 views17 pages

Using Beans in JSP: BY Sana Mateen

This document discusses how to use Java beans in JSP pages. It explains that Java beans are reusable Java components that separate business logic from presentation. The key requirements for a Java bean class are that it must implement Serializable or Externalizable, provide a no-arguments constructor, and have get/set methods for private properties. The three JSP actions for working with beans are <jsp:useBean> to instantiate a bean object, <jsp:setProperty> to set a bean property value, and <jsp:getProperty> to retrieve a bean property value.

Uploaded by

sana mateen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views17 pages

Using Beans in JSP: BY Sana Mateen

This document discusses how to use Java beans in JSP pages. It explains that Java beans are reusable Java components that separate business logic from presentation. The key requirements for a Java bean class are that it must implement Serializable or Externalizable, provide a no-arguments constructor, and have get/set methods for private properties. The three JSP actions for working with beans are <jsp:useBean> to instantiate a bean object, <jsp:setProperty> to set a bean property value, and <jsp:getProperty> to retrieve a bean property value.

Uploaded by

sana mateen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

USING BEANS IN JSP

BY
SANA MATEEN
JAVA BEANS
Java Beans are reusable java components that allow us to
separate business logic from presentation.
A JavaBean is nothing more than a class that maintains
some state data (called properties) and follows a certain set
of coding conventions.
Java Bean class meets the following requirement:
Must implement java.io.Serializable or
java.io.Externalizable
provide a no-arguments constructor
private properties must have corresponding get/set
methods
Three action elements are used to work with beans they
are:
useBean
setProperty
getProperty
useBean

A jsp action element <jsp:useBean> instantiates a javabean object into


jsp page.
<jsp:useBean id=object_name class=class_name
scope=page|request|session|application/>
The attribute scope specifies the area of visibility of the loaded bean.
<%class_name obj_name=new class_name();%>

Example:
<jsp:useBean id=fact scope=page class=bean.Factorial/>
Is equivalent to
<%bean.Factorial fact=new bean.Factorial()%>
setProperty
<jsp:setProperty> assigns a new value to the specified property of the
specified bean object.
<jsp:setProperty name=obj_name property=prop_name
value=prop_value/>
Is equivalent to
<%obj_name.setProp_name(prop_value)%>
To set a property of our bean object fact
<jsp:setProperty name=fact property=value value=5/>
Is equivalent to
<%fact.setValue(5);%>
getProperty
<jsp:getProperty> action element retrieves the value of specified
property of the specified bean object.
<jsp:getProperty name=obj_name property=prop_name/>
Is equivalent to
<%=obj_name.getProp_name();%>
<jsp:getProperty name=fact property=value/>
Is equivalent to
<%=fact.getValue();%>

You might also like