I am trying to get the exception in action class also.  I have previous
defined an error page that displays the error and have user type in more
information and click a button to email to support.  That works fine.
But we also need to log exceptions.  So I tried to change the handler
from a jsp page to an action.  I have not got the error action to work.
It seems like the exception wrapper is no longer in the stack once the
action is invoked.  



-----Original Message-----
From: Matt Filion [mailto:[EMAIL PROTECTED] 
Sent: Monday, September 10, 2007 1:37 PM
To: Struts Users Mailing List
Cc: 'Struts Users Mailing List'
Subject: Re: How to get exception in action class for error page?

If your just going for exception information you can direct to a JSP
page 
and use the Struts tags and look directly at the attributes defined o
the 
Exception implementation.
<struts:property value="exception.message"/> 
<struts:property value="exception.cause.class"/> 

etc..


Matt Filion
[EMAIL PROTECTED]


------------------------------------------------------------------------
------------------------------------------------------------------------
--------------------------------
This is a PRIVATE message. If you are not the intended recipient, please

delete without copying and kindly advise us by e-mail of the mistake in 
delivery. NOTE: Regardless of content, this e-mail shall not operate to 
bind CSC to any order or other contract unless pursuant to explicit 
written agreement or government initiative expressly permitting the use
of 
e-mail for such purpose.
------------------------------------------------------------------------
------------------------------------------------------------------------
--------------------------------




"Neil Aggarwal" <[EMAIL PROTECTED]> 
09/10/2007 07:46 AM
Please respond to
"Struts Users Mailing List" <user@struts.apache.org>


To
"'Struts Users Mailing List'" <user@struts.apache.org>
cc

Subject
How to get exception in action class for error page?






Hello:

I declared an application error page in my web.xml:

  <error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error.action</location>
  </error-page>

I have this declaration in my struts.xml:

    <action name="error" class="page.Error">
      <result name="success" type="tiles">error</result>
    </action>

In my page.Error class, I am trying to get the exception
that was thrown:

public class Error extends ActionSupport {
  public String execute() {
    PageContext pageContext = ServletActionContext.getPageContext();
    if( pageContext != null ) {
      Exception exception = pageContext.getException();
      if( exception != null ) {
        Logger.getLogger(getClass()).error(exception);
      }
    } else {
      Logger.getLogger(getClass()).debug("Page context is null");
    }
    return SUCCESS;
  }
}

But, when the action executes, the pageContext is always null.

What can I do to get the exception that was thrown?

Thanks,
                 Neil

--
Neil Aggarwal, (832)245-7314, www.JAMMConsulting.com
Eliminate junk email and reclaim your inbox.
Visit http://www.spammilter.com for details.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to