The problem is that, once a page starts writing back to the browser, you
can't do a forward, which is effectively what any error handling mechanism
will try to do. If you look at the generated code, you will see a big
try/catch block around the body of the _jspservice() method. What this does
is try to forward to an error page if an exception is thrown inside the
method. Failing this, WebSphere itself can be configured with an error page
to forward to if it catches an exception. The problem is exasperated if you
are using dynamic includes. A dynamic include will force a flush (write back
to the browser) at the point where the the dynamic include starts and at the
end of the include (I think). Once you have passed the first flush, you
can't forward.
I think there is a lot to be said for using the jsp purely as a "view" ie.
no business logic. There is less chance of something going wrong then. Also
I guess defensive coding that attempts to handle any errors within the jsp
is a good approach.
As far as I know, there isn't really a good solution to this one (anyone
else??).
Cheers,
Glen.
"Curtis Witherow" <with...@cecomet.net> wrote in message
news:3D5C12E5...@cecomet.net...
Hi all,
I'm running WC v5.4PE on Windows NT.
Can anyone give me some insight on capturing and handling errors in JSP's?
In the Programmer's Guide, three levels of JSP error handling are outlined:
1) Handle errors within page (I.E. try/catch);
2) Page level ("errorPage" and "isErrorPage" attributes);
3) Application level (GenericApplicationError & GenericSystemError views).
I can handle level 1 and level 3 is automatic, but I'm having trouble with
"page level". If an error occurs very early in the JSP processing, the
appropriate error page is displayed. But if the error occurs later in the
processing, the page generation will die, a portion of originally requested
page is displayed in the browser and the following message will be placed in
my log:
Message Text: CMN1244E An error occurred when forwarding document
tl/order/OrderList.jsp. javax.servlet.ServletException: ERROR: Cannot
forward. Response already committed.
<<stack trace omitted>>
I think the problem has to do with buffering. I've attempted to make the
buffer larger by adjusting the buffer attribute, but with no success.
Does anyone have any ideas?
=================================
Code snippet from main JSP:
<%
// OrderList.jsp -
%>
<%@ page errorPage="../errors/FeatureNotAvailableError.jsp" autoFlush="true"
buffer="8k" %>
...
=================================
Code snippet from error handler JSP:
<%
// FeatureNotAvailableError.jsp -
%>
<%@ page isErrorPage="true" %>
...
=================================
--
Curtis Witherow
CCA, Inc.