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 |