Java Reference
In-Depth Information
ServletContext servletContext = getServletContext ();
RequestDispatcher dispatcher=null;
if (postList.getSize()>0) {
dispatcher=
servletContext.getRequestDispatcher(
"/JSP/ShowBoardResults.jsp");
} else {
dispatcher = servletContext.getRequestDispatcher("/JSP/
NotFoundResults.jsp");
}
dispatcher.forward(request, response);
We can begin to see the benefits of chapter 4's refactored solution. Though
we changed the class names in this example to make it easier for us (and you)
to manage the many examples in the topic, we probably wouldn't change
them in a real-world revision. The model-view-controller architecture has
effectively insulated different parts of the application from major change.
We're adding significant new functionality, and yet the solution continues to
flow easily.
The JSP for ShowBoard
Next, we'll look at the primary revisions in our JSP . We renamed PostList-
Results.jsp to ShowBoardResults.jsp :
<TABLE border="1">
<TR>
<TD>Subject</TD>
<TD>Author</TD>
<TD>Number</TD>
</TR>
<% for (int i=0; i < ShowBoardCommand.getSize(); i++) { %>
<TR> <TD>
<A href=bbs.ShowThreadController?
parent=<%=ShowBoardCommand.getNumber(_i) %>>
<%=ShowBoardCommand.getSubject(_i) %></A></TD>
<TD><%=ShowBoardCommand.getAuthor(_i) %></TD>
<TD><%=ShowBoardCommand.getNumber(_i) %></TD>
</TR>
<% } %>
</TABLE>
<A href="../JSP/reply.jsp?parent=0&
board=<%=ShowBoardCommand.getBoard()%>" >
Post a top level message</A>
We added a table column for the post number and a link for replies, and we
linked the subject line to ShowThreadController , which retrieves a thread and
Search WWH ::




Custom Search