Java Reference
In-Depth Information
T
ABLE
16.2
Continued
Attribute
Definition
The
param
attribute represents the name of the request parameter whose
value you want to set the named property to. A
<jsp:setProperty>
action
cannot have both
param
and
value
attributes referenced in the same action.
param
The
value
attribute represents the value assigned to the named bean's
property.
value
The
<jsp:getProperty>
Standard Action
The last standard action that references JavaBeans in JSPs is <
jsp:getProperty>
. It takes the
value of the referenced bean instance's property, converts it to a
java.lang.String
, and places
it into the implicit
out
object. The referenced bean instance must be defined and in scope
before this action references it. The syntax for the <
jsp:getProperty>
action is as follows:
<jsp:getProperty name=”
name
” property=”
propertyName
” />
Table 16.3 contains the attributes and their descriptions for the <
jsp:getProperty>
action.
T
ABLE
16.3
The Attributes for the
<jsp:getProperty>
Action
Attribute
Definition
This attribute represents the name of the bean instance from which the
property is obtained, defined by a
<jsp:useBean>
action or some other
action.
name
This attribute represents the bean property for which you want to get a
value.
property
A JSP Example Using JavaBeans
In this example, you'll use a simple JavaBean that acts as a counter. It has a single
int
prop-
erty,
count
, which holds the current number of times the bean's property has been accessed. It
also contains the appropriate methods for getting and setting this property. Listing 16.1 con-
tains the source code for the
Counter
bean.
L
ISTING
16.1
Counter.java
public class Counter {
// Initialize the bean on creation
int count = 0;