JSP tags

Hi,

What is the jsp:useBean class id and scope used for?

What is the jsp:setProperty name property and param for too?

Thanks.
jedistarAsked:
Who is Participating?
 
mukundha_expertConnect With a Mentor Commented:
<jsp:useBean class = "ClassName" ID = "instanceName" >

is equivalent to your java code

  ClassName instanceName = new ClassName ();

you can reference the instanceName Object in ur jsp according to the scope u give.

<jsp:setProperty name = "instanceName" property = "beanProperty" param = "data1">

is equivalent to calling the setBeanProperty method as shown below,
instanceName.setbeanProperty ( data1 );

similarly jsp:getProperty  tag is used to access the properties of the bean
0
 
KantiCommented:
0
 
mukundha_expertCommented:
supose u ve a customer bean say
Customer { name,  age, address } with all getters and setters for that.

you have a html form contining all the fields of customer in that. when you submit it to your jsp, the JSP can map the input paramters ( form values ) directly to the bean using these tags.

suppose if your form fields also have the same names as of customer ( name,age,address )

you can call

   <jsp:useBean class = "Customer" ID = "customer" >
  <jsp:setPropert name = "customer" property = "*" />

the tags above will create a beanInstance customer and name,age,address are set to the values as specified in the form.

0
 
mukundha_expertCommented:
Forgot to mention the SCOPE .

it can be page,request or session

if its page scope then the bean will be available only in that page
if it is request scope then the bean will be available only in the request
if it is session scope then the bean is available throught the session.

the default scope is page scope
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.