Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSP: error page exception.getMessage returning null for setProperty excepti

843836Oct 12 2004 — edited Oct 14 2004
Hey all,

I have a little problem. My error page (JSP) seems to not be getting the
exception text for some reason when my beans throw exceptions in the setters
and I use setProperty. The errors do fine when I use other methods. This is
the only case in which they aren't working.
Here's the setup. Can someone tell me what I'm doing wrong?

In the bean: (many similar methods; this one is generic for illustrative
purposes)
   public void setField(String str) throws IllegalArgumentException
   {
      // limit 10 chars (null allowed)
      if (str!= null && str.length() > 10)
      {
         throw new IllegalArgumentException(
            "Field must be 10 characters or less.");
      }
      this.field = str;
   }
In the JSP:
<%@ page isErrorPage="false" errorPage="err.jsp" %>
...
<jsp:useBean id="myBean" class="myPackage.myBean" scope="page" />
<jsp:setProperty name="myBean" property="*" />
<% myBean.testUpdate(s.getPerms()); %>

Err.jsp (note that "exception" is an intrinsic JSP object, like "out")
<p class="bigAttention">Message: <%= exception.getMessage() %></p>

When exceptions are thrown from the testUpdate method in the bean, they
forward just fine to err.jsp. When thrown from the setters, I get null when I
try exception.getMessage (or just JasperException when I do toString).

Sample from using toString:
---------------------------------
Message: org.apache.jasper.JasperException

Stack Trace: org.apache.jasper.JasperException at
org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper
(JspRuntimeLibrary.java:199) at
---------------------------------


When testUpdate fails:
---------------------------------
Message: This operation requires permissions. You either have VIEW
permissions or aren't logged in. Please LOG IN if you haven't, then try
again.

Stack Trace: java.lang.IllegalAccessException: This operation requires
permissions. You either have VIEW permissions or aren't logged in. Please LOG
IN if you haven't, then try again. at
---------------------------------

When I used getMessage, it was similar, but Message was null instead of
JasperException.

When I set the property myself, like
<% myBean.setField("valuethatshouldthrowexception"); %>
it all works fine.

WTF?
Anyone?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 11 2004
Added on Oct 12 2004
3 comments
349 views