JspException in custom tag  
Author Message
kingkong





PostPosted: 2006-3-25 8:38:00 Top

java-programmer, JspException in custom tag Hello,

Can someone show me the error of my ways.....

I have a custom tag 'public int doStartTag() throws JspException' from
which a JspException is thrown. The exception is forwarded to an JSP
error page and from there I want to (eventually) shove the contents of
the exception into a javabean.

My javabean is set up as follows:

public class errorBean
{
Throwable errorObject = null;
String errorMessage = null;

public void setErrorObject(Throwable errorObject)
{
this.errorObject = errorObject;
errorMessage = errorObject.getMessage();
}
public String getErrorMessage()
{
return errorMessage;
}
} //errorBean


My JSP error page looks like:

<%@ page isErrorPage="true" %>

<html>
<body>

<jsp:useBean id="errorBean" class="errorBean"/>
<jsp:setProperty name="errorBean" property="errorObject"
value="${pageContext.errorData.throwable}"/>
The error message is <jsp:getProperty name="errorBean"
property="errorMessage"/>


</body>
</html>

When I throw an exception like 'throw new JspException("Hello World")'
in my custom tag,
everything seems to work i.e. "Hello World" shows up in my Mozilla &
Netscape browser.
When I throw an exception like 'throw new JsPException("Hello
World",throwableObject)
where throwableObject subclasses Throwable, I get a 'http status 500'
error, but the browser clearly displays as part of a stack trace (?)
the exception "Hello World" as well as the root cause.

Why would this work in one case ('throw new JspException("Hello
World")' and other
('throw new JsPException("Hello World",throwableObject)) fail to
display "Hello World"?

Thnaks for any help.