Got it! Thanks for the details...


-----Original Message-----
From: Will Spies/Towers Perrin [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 10, 2001 10:17 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: Debugging struts exceptions




I mean in all your JSPs use the following tag in the beginning:

<%@ page language="java" errorPage="error.jsp" %>


Then, in error.jsp you can use the following code:

....
<% Throwable strutsException = (Throwable) request.getAttribute
("org.apache.struts.action.EXCEPTION");%>
<% if ( strutsException != null ) {%>
<p>Struts trace was: <br><pre>
<%=getStackTraceAsString(strutsException)%><b>
<%} else {%>
<p>No Struts trace
<%}%>


<%!
String getStackTraceAsString(Throwable e)
{
    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
    e.printStackTrace(new PrintStream(ostr));
    return(ostr.toString());
}
%>
....

Note: this is just a snipet of the error.jsp but this should give you the
idea. You'll find more info on the errorPage directive in the JSP guides.
The only reason I used Throwable above rather than the struts exception
itself was because I already had this method and was using it for other
exceptions.







 

 

                                                      To:
[EMAIL PROTECTED]                                    
                    [EMAIL PROTECTED]        cc:     (bcc: Will
Spies/Towers Perrin)                                   
                    elheim.com                        Subject:     RE:
Debugging struts exceptions                              
 

                    04/10/01 09:15 AM

                    Please respond to

                    struts-user

 

 





What exactly do you mean by "declare an error page"?  Is this a JSP that is
specified as a global forward in struts-config.xml or a servlet param in
web.xml?

thanks,
Bob

-----Original Message-----
From: Will Spies/Towers Perrin [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 10, 2001 7:33 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: Debugging struts exceptions





I actually found a good solution to this. Looking at the taglib code I
found this code all over the place when they throw exceptions:

 pageContext.setAttribute(Action.EXCEPTION_KEY, e,
PageContext.REQUEST_SCOPE);

I don't know if this is documented somewhere. Probably it is and I just
missed it. However, this allowed me to create an errorPage which displays
*THIS* exception. So, now all my JSPs have an errorPage declared that that
yanks this exception out of the request and displays it. Although sometimes
this exception isnt' great it's far far better than the original one.

Thanks, I forgot to post this.

Will










                                         To:
[EMAIL PROTECTED]
                    "Craig R.            cc:     (bcc: Will Spies/Towers
Perrin)
                    McClanahan"          Subject:     Re: Debugging struts
exceptions
                    <craigmcc@apa

                    che.org>



                    04/09/01

                    10:32 PM

                    Please

                    respond to

                    struts-user










On Wed, 4 Apr 2001, Will Spies/Towers Perrin wrote:

>
>
> I didn't get any response so I'm going to try again. Here is another
> exception:
>
> Wed Apr 04 10:53:26 EDT 2001:<E> <WebAppServletContext-tpsampleapp> Root
> cause of ServletException
> javax.servlet.ServletException: runtime failure in custom tag 'form'
>      at jsp_servlet._employee._jspService(_employee.java, Compiled Code)
>      at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)

You might want to complain to WebLogic about this.

The actual exception that is thrown *does* contain a more useful error
message -- it's just that WebLogic is not telling you about it.

Alternatively, you can declare an error page to handle runtime
errors.  The Struts tags that throw exceptions store a copy of the
underlying exception as a request attribute under key
"org.apache.struts.action.EXCEPTION", so you can display it yourself.

Craig McClanahan







Reply via email to