You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Neil Aggarwal <ne...@JAMMConsulting.com> on 2007/09/10 16:46:48 UTC
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: How to get exception in action class for error page?
Posted by "Jiang, Jane (NIH/NCI) [C]" <ji...@mail.nih.gov>.
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:mfilion@csc.com]
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
mfilion@csc.com
------------------------------------------------------------------------
------------------------------------------------------------------------
--------------------------------
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" <ne...@JAMMConsulting.com>
09/10/2007 07:46 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
"'Struts Users Mailing List'" <us...@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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to get exception in action class for error page?
Posted by Matt Filion <mf...@csc.com>.
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
mfilion@csc.com
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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" <ne...@JAMMConsulting.com>
09/10/2007 07:46 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
"'Struts Users Mailing List'" <us...@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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org