Java Reference
In-Depth Information
%>
<TD>*** No orders placed! ***</TD>
</TR>
<%
}
else
{
%>
<TR STYLE="background-color:yellow">
<TD></TD> <!-- Blank cell -->
<TD>Total cost:</TD>
<TD>
<%= String.format("%.2f",totalCost) %> </ TD>
</TR>
<%
}
%>
</TABLE>
</BODY>
</HTML>
Actually, there is really more Java code here than there should be in any JSP. The
material on the use of JavaBeans in JSPs in the latter part of the next chapter should
serve to demonstrate how this problem may be solved.
9.7
Error Pages
In common with other network software, JSPs can generate errors for a variety of
reasons, even when all syntax errors have been eradicated. For example, a database
connection can fail or the user can enter invalid data. Ideally, our software should be
able to handle such situations in a graceful manner by supplying a meaningful mes-
sage for the user and, if possible, providing him/her with a way to recover from the
situation (possibly by re-entering data). As things stand at present in our shopping
cart application, the generation of an exception by our code will result in a non-
helpful error page being served up by Tomcat in the user's browser (often, but not
always, relating to error 500). In fact, some JSP containers do not even provide this
much assistance to the user.
Consequently, instead of relying upon the error-handling facilities provided by
the JSP container (which will not be user-orientated), we should try to handle excep-
tions gracefully in our own code. We could use a servlet to build up an error page
and redirect control to this page, but this is not necessary. A way of handling errors is
provided by the JSP specifi cation in the form of programmer-designated error pages,
the contents of which are created by the programmer. To associate an error page
Search WWH ::




Custom Search