Java Reference
In-Depth Information
Listing 3.6
Wrapping the model logic with commands
o JSPs mix HTML
with inline Java
content.
<HTML>
<HEAD>
<TITLE>Message Board Posts</TITLE>
</HEAD>
<H1>All Messages</H1>
<P>
<jsp:useBean id="postListCommand" class="bbs.PostListCommand"
scope="request"></jsp:useBean>
o
The <jsp:usebean>
tag identifies beans
we pass in.
<TABLE border="1">
<TR>
<TD>Subject</TD>
<TD>Author</TD>
<TD>Board</TD>
</TR>
<% for (int _i=0; _i < postListCommand.getSize(); _i++) { %>
<TR> <TD><%=postListCommand.getSubject(_i) %></TD>
<TD><%=postListCommand.getAuthor(_i) %></TD>
<TD><%=postListCommand.getBoard(_i) %></TD>
</TR>
<% } %>
</TABLE>
<P>
</BODY>
o
The <% %> tags
bracket Java code.
</HTML>
This program is almost pure HTML , with very few exceptions. One JSP tag
references the bean, and five process the loop that prints the table rows. That's
it. A good web designer would have no problem writing the short looping
code, and the programmer needs to know next to nothing about the web page
designs. The JSP will be compiled to servlet form and will look very similar to
our BreakOutCommand servlet.
With this last change, we have refactored our original solution to adapt it to
the Triangle design pattern. The solution closely resembles the reliable model-
view-controller architecture, with a full interaction controller, a command that
wraps the model, an HTML page for the input view, and a JSP page for the out-
put view. We will be able to change our model and view independently.
Search WWH ::




Custom Search