The J2EETM Tutorial
Home
TOC
PREV TOC NEXT Search
Feedback

Creating and Using a JavaBeans Component

You declare that your JSP page will use a JavaBeans component using either one of the following formats:

<jsp:useBean id="beanName"
	class="fully_qualified_classname" scope="scope"/> 

or

<jsp:useBean id="beanName"
	class="fully_qualified_classname" scope="scope">
	<jsp:setProperty .../>
</jsp:useBean> 

The second format is used when you want to include jsp:setProperty statements, described in the next section, for initializing bean properties.

The jsp:useBean element declares that the page will use a bean that is stored within and accessible from the specified scope, which can be application, session, request or page. If no such bean exists, the statement creates the bean and stores it as an attribute of the scope object (see Scope Objects). The value of the id attribute determines the name of the bean in the scope and the identifier used to reference the bean in other JSP elements and scriptlets.

The following element creates an instance of Currency if none exists, stores it as an attribute of the application object, and makes the bean available throughout the application by the identifier currency:

<jsp:useBean id="currency" class="util.Currency"
	scope="application"/> 
Home
TOC
PREV TOC NEXT Search
Feedback