Java Reference
In-Depth Information
Notice how the if-else construct is broken up into three separate
scriptlets—that is, snippets of code. Between them, in the body of the if and
the else , is plain HTML. Here is what that will get translated into after the
JSP conversion:
if (acct != null) { // acct.getParent()
out.println("<a href=\"BudgetPro?func=back\">");
out.println("<img src=\"/back.gif\">");
out.println("</a>");
} else {
out.println("<img src=\"/back.gif\">");
}
Do you also see why we describe it as being “turned inside out”? What
was delimited becomes undelimited; what was straight HTML becomes
delimited strings in output statements.
As long as we're on the topic of conversion, let's consider comments.
There are two ways to write comments in JSP, either in HTML or in Java. In
HTML we would write:
<!-- HTML comment format -->
but since we can put Java inside of delimiters, we can use Java comments, too:
<% // Java comment format %>
or even:
<% /*
* Larger comments, too.
*/
%>
If you've been following what we've been saying about translation of JSP
into Java code, you may have figured out the difference. The Java comments,
when compiled, will be removed, as all comments are, from the final executable.
The HTML-based comments, however, will be part of the final HTML
output. This means that you'll see the HTML comments in the HTML that
reaches the browser. (Use the View Source command in your browser to see
them. As HTML comments, they aren't displayed on the page, but they are
sent to the browser.) This is especially something to be aware of when writing
a loop. Remember our loop for generating the table?
Search WWH ::




Custom Search