This is a tough one - at least for me and the best Java/JSP developers in my
department.
My web application makes use of many custom classes implemented as beans and
invoked via <jsp:useBean ..../>. Many of these classes catch and rethrow
exceptions, adding descriptive text along the way. For example, the
constructor in class Foo populates a HashTable with info from an SQL
database:
public Foo() throws SQLException
{
try
{
// SQL stuff here
}
catch (SQLException sqle)
{
throw new SQLException("Problem getting db connection in Foo(): " +
sqle.getMessage());
}
}
JSP files include this line:
<jsp:useBean id="myFoo" class="com.myproject.Foo" scope="whatever"/>
If i do *not* have a JSP error page declared, when Foo's constructor throws
an SQLException, JRun displays a page beginning with this text:
javax.servlet.ServletException: <jsp:useBean> on line '7' failed.
java.lang.Exception: Problem getting db connection in Foo(): (re-thrown
exception message here)
at com.myproject.Foo (Foo.java: 10)
.... followed by the rest of the stack trace. This is very useful for me, but
not for user's eyes.
So i created a JSP error page and invoke it via <%@ page errorPage= ...%>
It puts the exception text and stack dump into a mail message and sends it
to me and displays a user-friendly generic error message.
in the JSP error page, i use exception.getMessage() and
exception.printStackTrace(printwriter) to construct the mail message.
Unfortunately, the stack dump looks something like this:
javax.servlet.ServletException: <jsp:useBean> on line '7' failed.
at
allaire.jrun.jsp.JRunJSPStaticHelpers.makeException(JRunJSPStaticHelpers.jav
a:615)
at
allaire.jrun.jsp.JRunJSPStaticHelpers.makeUBException(JRunJSPStaticHelpers.j
ava:573)
at
allaire.jrun.jsp.JRunJSPStaticHelpers.createBean(JRunJSPStaticHelpers.java:2
78)
at
allaire.jrun.jsp.JRunJSPStaticHelpers.getAndSetBean(JRunJSPStaticHelpers.jav
a:221)
etc. In other words, i lose all my explanatory text.
Interestingly, stack dumps that are generated by scriptlets rather than
<jsp:useBean.../> don't show this behavior - they're the same in my email as
they appear in the browser.
Can someone explain why it works this way, or better yet, how i can get my
custom exception messages when <jsp:useBean.../> throws an exception? Is
this the case for all exceptions thrown by JSP tags (as opposed to
scriptlets)?
many thanks in advance...
Joe Niski | Senior Software Engineer/Internet Architect
503.548.2176
CYBERSIGHT
strategy . marketing . design . technology
los angeles . portland . san francisco . toronto
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists