O'Reilly logo

JavaServer Pages, Second Edition by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

<jsp:useBean>

Synopsis

The <jsp:useBean> action associates a Java bean with a name in one of the JSP scopes and also makes it available as a scripting variable. An attempt is first made to find a bean with the specified name in the specified scope. If it’s not found, a new instance of the specified class is created.

Syntax 1: Using a concrete class, no body

<jsp:useBean id="beanVariableName" class="className"
  [scope="page|request|session|application"] />

Syntax 2: Using a concrete class, with a body

<jsp:useBean id="beanVariableName" class="className"
  [scope="page|request|session|application"]>
  Evaluated if a new instance is created
</jsp:useBean>

Syntax 3: Using a type and optionally a class or a serialized bean, no body

<jsp:useBean id="beanVariableName" type="className" 
  [class="className" | beanName="className"]
 [ scope="page|request|session|application"] />

Syntax 4: Using a type and optionally a class or a serialized bean, with a body

<jsp:useBean id="beanVariableName" type="className" 
  [class="className" | beanName="className"]
  [scope="page|request|session|application"]>
  Evaluated if a new instance is created
</jsp:useBean>

Attributes

Attribute name

Java type

Dynamic value accepted

Description

beanName
String

RT expression

The name of the bean, as expected by the instantiate( ) method of the Beans. class in the java.beans package

class
String

No

The fully qualified class name for the bean

id
String

No

The name to assign to the bean in the specified scope, as well ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required