View Single Post
  #3 (permalink)  
Old 08-09-2007, 07:54 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Default Re: How can we use beans in JSP?

Jsp provides as approach to utilizing javabeans that is based on the concept of tags. These are really no more complicated than
the standard html tags; they have a name and they take attributes.
There are three tags provided by the specification to support the use of javabeans in your jsp pages:
1. <jsp:usebean>
2.<jsp:setproperty>
3.<jsp:getproperty>.

Example : Javabean class.

import java.io.Serializable;
public class CarBean implements Serializable
{
private String make = "Ford";
public CarBean()
{}
public String getMake()
{
return make;
}

public void setMake(String make)
{
this.make = make;
}

}

Jsp page:
<html>
<head> <title> Using a bean</title> </head>
<body>
<jsp:usebean id = "MyCar: Class = "CarBean"/>
I have a <jsp:getproperty name = "MyCar" property = "make" />
<jsp:setproperty name = "MyCar" property = "make" value = "Ferrari" />
Now I have a <jsp:getproperty name = "MyCar" property = "make" />
</body>
</html>

output:
--------------
Using a bean

i have a Ford
Now i have a Ferrari
Reply With Quote