jsp:useBean | |
A jsp:useBean action is used to associate a JavaBean with the JSP. It ensures that the object is available for the appropriate scope specified in the tag. The bound object can be referenced from the JSP using the id it is associated with (or even from other JSPs, depending on the scope). Internally, the container first tries to locate the object using the id and scope and, if it is not found, uses the name of the bean as an argument to the instantiate() method of the java.beans.Beans using the current class loader. (If this instantiation fails, a request-time exception due to the instantiate() is thrown.) <jsp:useBean id="name" scope="page|request|session|application"
beandetails />
Where beandetails is one of:
<jsp:useBean id="mparam" scope="session" class="java.lang.String"> This is used to initialize the bean... </jsp:useBean> |
id | |
The case sensitive name used to identify the object instance. |
scope | |||||||||||||||||||
Default: page | |||||||||||||||||||
The scope within which the reference is available.
|
class | |
The fully qualified class name. |
beanName | |
The name of a Bean, as you would supply to the instantiate() method in the java.beans.Beans class. This attribute can also be a request time expression. It is permissible to supply a type and a beanName, and omit the class attribute. The beanName follows the standard bean specification and can be of the form "a.b.c", where "a.b.c" is either a class, or the name of a serialized resource in which case it is resolved as "a/b/c.ser" (see the JavaBeans specification). |
Type | |
Default: Same as the value of the class attribute. | |
This optional attribute specifies the type of the class, and follows standard Java casting rules. The type must be a superclass, an interface, or the class itself. Just like any casting operation, if the object is not of this type then java.lang.ClassCastException can be thrown at request time. |