The <jsp:useBean> standard action defines a variable that holds a reference to either an existing bean attribute or, if the bean doesn’t already exist, a new bean.
The <jsp:useBean> MUST have an “id” attribute which declares the variable name that’ll be used in this JSP to refer to the bean.
If you don’t include a “scope” attribute with <jsp:useBean>, the scope defaults to page scope.
The “class” attribute is optional, and it declares the class type that will be used if a new bean is created. The type must be public, non-abstract, and have a public no-arg constructor.
If you put a “type” attribute in <jsp:useBean>, it must be a type to which the bean can be cast.
If you have a “type” attribute but do NOT have a “class” attribute, the bean must already exist, since you haven’t specified the class type that should be instantiated for the new bean.
The <jsp:useBean> tag can have a body, and anything in the body runs ONLY if a new bean is created as a result of <jsp:useBean> (which means that no bean with that “id” was found in the specified (or default) scope).
The main purpose of the body of <jsp:useBean> is to set the new bean’s properties, using <jsp:setProperty>.
<jsp:setProperty> must have a name attribute (which will match the “id” from <jsp:useBean>), and a “property” attribute. The “property” attribute must be either an actual property name or the wildcard “*”.
If you don’t include a “value” attribute, the Container will set the property ...
With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, interactive tutorials, and more.