Java Reference
In-Depth Information
postList.initialize();
postList.execute();
request.setAttribute("CompoundJSPCommand", postList);
ServletContext servletContext = getServletContext ();
String resultsPage;
if (postList.getSize() > 0) {
resultsPage = "/JSP/BoardResults.jsp"; B Decision 1
} else {
resultsPage = "/JSP/NotFoundResults.jsp"; C Decision 2
}
RequestDispatcher dispatcher =
servletContext.getRequestDispatcher (resultsPage);
dispatcher.forward(request, response);
} catch (Throwable theException) {
theException.printStackTrace();
}
}
B The first decision processes the expected case. Note that in the same section of
code we are able to determine what triggered the condition and the actions that
can occur.
Command
Servlet
if (command.x = a){
call JSP a;
JSP a
else if (command.x = b){
call JSP b;
JSP b
Client
HTML
Figure 4.2 It is better to process decisions in the controller servlet than within the JSP.
Simplicity and better tool integration are goals of JSP design.
Search WWH ::




Custom Search