Java Reference
In-Depth Information
return acctDetails;
}
public int getNumAccounts()
{
/*
Dividing the number of objects in the Vector
holding the data by the number of table fi elds
will produce the number of rows (and so the
number of accounts) in the database table…
*/
return acctDetails.size()/NUM_FIELDS;
}
}
For consistency (and to save an unnecessary effort of imagination!), the corre-
sponding JSP will be named JDBC X .jsp . The name of the error page will be changed
in a similar fashion (with appropriate creation of this new, but identically-coded,
error page) and the name of the bean will also be changed in the <jsp:useBean>
tag. The lines containing these minor changes are shown below (with the changes
marked in bold).
<%@ page language="java" contentType="text/html"
errorPage="JDBC X Error.jsp" %>
<jsp:useBean id="data" class="jdbc.JDBCBean X " />
In order to use the JSP to access the numAccounts property and display the result
it returns, the following lines must be placed after the </TABLE> tag in the
original JSP:
Number of accounts held:
<p STYLE="color:blue">
<jsp:getProperty name="data" property="numAccounts" />
</P>
The resultant output is shown in Fig. 10.6 .
For the <jsp:setProperty> tag, three attributes are commonly required:
￿ name (of bean, as before);
￿ property (as before);
￿ value (to be assigned to the property).
The example below sets the balance property of a bean called account to 0.
<jsp:setProperty name="account" property="balance" value="0" />
Instead of setting the property to a literal value, though, we often need to set it to
a parameter value passed to the JSP (possibly via a form), provided that the param-
eter has the same type as the property (or can be converted into that type). There are
three ways of doing this…
Search WWH ::




Custom Search