Explain how to use JavaBeans components (beans) from a JSP page

Explain how to use JavaBeans components (beans) from a JSP page?

The JSP specification includes standard tags for bean use and manipulation.

<jsp:useBean> creates an instance of a specific JavaBean class. If the instance already exists, it is retrieved. Otherwise, a new instance of the bean is created.

<jsp:setProperty> and <jsp:getProperty> are used to manipulate properties of a specific bean.

Explain how to use JavaBeans components (beans) from a JSP page.

Java beans are reusable components. Java beans are utilized to isolate business logic from the presentation logic. It is just a class with a set of setters and getters with a public constructor.

JSP provides three tags to handle java beans.
<jsp:useBean id=“bean name” class=“bean class” scope = “page | request | session |application ”/>
Where the bean name is to refer the bean, bean class is the java class in which the bean is defined. Scope is the restricted location to where the bean is visible.
<jsp:setProperty name = “id” property = “someProperty” value = “someValue” />
Where id is the name of the bean specified by useBean tag, property is the property that is to be passed
<jsp:getProperty name="beanInstanceName" property="propertyName" />
Where beanInstanceName is the name of bean instance variable, property name is the property that is to be referred.
What is the jspInit() method?
The jspInit() method of the javax.servlet.jsp. JspPage interface is similar to the init() method of servlets..
JSP Actions - Explain JSP Actions in brief.
JSP actions can be used to print a script expression, create and store a Java Bean and for many other...
Difference between custom JSP tags and beans
Custom JSP tag is a user defined tag describing the way its attributes and its body are interpreted...
Post your comment