Java Reference
In-Depth Information
for (Iterator actit = acct.getAllSubs(); actit.hasNext(); ) {
Account suba = (Account) actit.next();
sb.append("<tr>");
sb.append("<td><a href=\"BudgetPro?name="+suba.getName());
sb.append("&func=cd\">");
sb.append(suba.getName());
sb.append("</a></td>");
sb.append("<td>albing</td>");
sb.append("<td>");
sb.append(suba.getTotal().toString());
sb.append("</td>");
sb.append("</tr>\n");
} // next acct
That would be hard to do with file-based HTML.
Another approach, the one used by JavaServer Pages, would be to use the
HTML file as input to a converter program—one which would take each line
of HTML, for example
<input name="name" size="20">
and produce a line of Java code:
out.println("<input name=\"name\" size=\"20\">");
Notice how the converter would be the one to handle the escape sequence
for the quotation marks; we get to write straight HTML—it has to deal with
the backslashes.
This is the basic idea behind JavaServer Pages. JSP files are nothing more
than HTML (with some additions that we'll discuss shortly) which are com-
piled into Java programs—servlets, to be exact—that are then run to produce
the Web page. The conversion happens no later than the first time the Web
server tries to serve up that JSP. If it hasn't yet been converted, it will convert
it into Java code and start the servlet. Thereafter, other requests to that page go
directly to the servlet. If you modify the JSP file, then the Web server recognizes
that the file has been modified and reconverts it.
But why go to all this trouble? It's not for the static HTML that we need
JSP, but rather for the dynamic bits. Remember that for loop, above, used to
make the HTML table of subaccounts? Let's look at part of a JSP that does the
same thing:
Search WWH ::




Custom Search