Java Reference
In-Depth Information
Listing 3.6
Wrapping the model logic with commands
o JSPs mix HTML
with inline Java
<TITLE>Message Board Posts</TITLE>
<H1>All Messages</H1>
<jsp:useBean id="postListCommand" class="bbs.PostListCommand"
The <jsp:usebean>
tag identifies beans
we pass in.
<TABLE border="1">
<% for (int _i=0; _i < postListCommand.getSize(); _i++) { %>
<TR> <TD><%=postListCommand.getSubject(_i) %></TD>
<TD><%=postListCommand.getAuthor(_i) %></TD>
<TD><%=postListCommand.getBoard(_i) %></TD>
<% } %>
The <% %> tags
bracket Java code.
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