j2ee: Using JavaBeans in JSPs [17/20] ![]() ![]() ![]() |
Declaring the Bean
<jsp:useBean> action
Locates or instantiates a bean with a specified name and scope.
Syntax:
<jsp:useBean id="name" scope="page|request|session|application" typeSpec /> typeSpec ::= class="className" | class="className" type="typeName" | type="typeName" class="className" | beanName="beanName" type="typeName" | type="typeName" beanName="beanName" | type="typeName"
class must be assignable to type if both are declared
If the useBean has a body, it is of the form:
<jsp:useBean id="name" scope="page|request|session|application" typeSpec > body </jsp:useBean>
The body will be invoked if the Bean is created.
Typically, the body will contain either scriptlets or jsp:setProperty tags that will modify the object created in the useBean tag
The contents of the body are not restricted.
Semantics:
<jsp:useBean>
element
has a non-empty body, the body is processed.