Java Reference
In-Depth Information
<% // for each subaccount:
for (Iterator actit = acct.getAllSubs(); actit.hasNext(); ) {
Account suba = (Account) actit.next();
%>
<!-- Next Row -->
<tr>
<td><a href="BPControl?name=<%= suba.getName() %>&func=cd">
...
<% } // next acct %>
We've put a comment just prior to the <tr> tag. What will happen is that
the comment will be part of the generated HTML, and since this is a loop, the
comment, just like the <tr> and other tags, will be repeated for each iteration
of the loop. Now we're not saying this is undesirable—in fact it makes the re-
sultant HTML more readable. But be aware that these comments will be visible
to the end user. Be careful in what you say in them. The additional transmission
time required for these few extra bytes is probably imperceptible, unless your
comments are large and repeated many times.
19.3.2
The other place that code can be placed is outside the doGet() and doPost() .
It is still inside the class definition for the servlet class that gets generated from
the JSP, but it is not inside any method. Such code is delimited like this:
Declaration
<%! code %>
The exclamation mark makes all the difference. Since it's outside any
method, such code typically includes things like variable declarations and
complete method declarations. For example:
<%! public static MyType varbl;
public long
countEm()
{
long retval = 0L;
retval *= varbl.toLong();
return retval;
}
%>
Search WWH ::




Custom Search