|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.struts.action.ExceptionHandler
public class ExceptionHandler
An ExceptionHandler is configured in the Struts
configuration file to handle a specific type of exception thrown by an
Action.execute
method.
Field Summary | |
---|---|
static String |
INCLUDE_PATH
The name of a configuration property which can be set to specify an alternative path which should be used when the HttpServletResponse has already been committed. |
static String |
SILENT_IF_COMMITTED
The name of a configuration property which indicates that Struts should do nothing if the response has already been committed. |
Constructor Summary | |
---|---|
ExceptionHandler()
|
Method Summary | |
---|---|
protected String |
determineIncludePath(ExceptionConfig config,
ActionForward actionForward)
Return a path to which an include should be attempted in the case when the response was committed before the ExceptionHandler
was invoked. |
ActionForward |
execute(Exception ex,
ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response)
Handle the Exception. |
protected void |
handleCommittedResponse(Exception ex,
ExceptionConfig config,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response,
ActionForward actionForward)
Attempt to give good information when the response has already been committed when the exception was thrown. |
protected void |
logException(Exception e)
Logs the Exception using commons-logging. |
protected void |
storeException(HttpServletRequest request,
String property,
ActionMessage error,
ActionForward forward,
String scope)
Default implementation for handling an ActionMessage
generated from an Exception during Action
delegation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String INCLUDE_PATH
The name of a configuration property which can be set to specify an alternative path which should be used when the HttpServletResponse has already been committed.
To use this, in your
struts-config.xml
specify the exception handler like
this:
<exception key="GlobalExceptionHandler.default" type="java.lang.Exception" path="/ErrorPage.jsp"> <set-property key="INCLUDE_PATH" value="/error.jsp" /> </exception>
You would want to use this when your normal ExceptionHandler
path is a Tiles definition or otherwise unsuitable for use in an
include
context. If you do not use this, and you do not
specify "SILENT_IF_COMMITTED" then the ExceptionHandler will attempt to
forward to the same path which would be used in normal circumstances,
specified using the "path" attribute in the <exception>
element.
public static final String SILENT_IF_COMMITTED
The name of a configuration property which indicates that Struts should do nothing if the response has already been committed. This suppresses the default behavior, which is to use an "include" rather than a "forward" in this case in hopes of providing some meaningful information to the browser.
To use this, in your
struts-config.xml
specify the exception handler like
this:
<exception key="GlobalExceptionHandler.default" type="java.lang.Exception" path="/ErrorPage.jsp"> <set-property key="SILENT_IF_COMMITTED" value="true" /> </exception>To be effective, this value must be defined to the literal String "true". If it is not defined or defined to any other value, the default behavior will be used.
You only need to use this if you do not want error information displayed in the browser when Struts intercepts an exception after the response has been committed.
Constructor Detail |
---|
public ExceptionHandler()
Method Detail |
---|
public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException
Handle the Exception. Return the ActionForward instance (if any) returned by the called ExceptionHandler.
ex
- The exception to handleae
- The ExceptionConfig corresponding to the exceptionmapping
- The ActionMapping we are processingformInstance
- The ActionForm we are processingrequest
- The servlet request we are processingresponse
- The servlet response we are creating
ActionForward
instance (if any) returned by
the called ExceptionHandler
.
ServletException
- if a servlet exception occursprotected void handleCommittedResponse(Exception ex, ExceptionConfig config, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response, ActionForward actionForward)
Attempt to give good information when the response has already been committed when the exception was thrown. This happens often when Tiles is used. Base implementation will see if the INCLUDE_PATH property has been set, or if not, it will attempt to use the same path to which control would have been forwarded.
ex
- The exception to handleconfig
- The ExceptionConfig we are processingmapping
- The ActionMapping we are processingformInstance
- The ActionForm we are processingrequest
- The servlet request we are processingresponse
- The servlet response we are creatingactionForward
- The ActionForward we are processingprotected String determineIncludePath(ExceptionConfig config, ActionForward actionForward)
Return a path to which an include should be attempted in the case
when the response was committed before the ExceptionHandler
was invoked.
If the ExceptionConfig
has the
property INCLUDE_PATH
defined, then the value of that
property will be returned. Otherwise, the ActionForward path is
returned.
config
- Configuration elementactionForward
- Forward to use on error
protected void logException(Exception e)
Logs the Exception
using commons-logging.
e
- The Exception to LOG.protected void storeException(HttpServletRequest request, String property, ActionMessage error, ActionForward forward, String scope)
Default implementation for handling an ActionMessage
generated from an Exception
during Action
delegation. The default implementation is to set an attribute of the
request or session, as defined by the scope provided (the scope from
the exception mapping). An ActionMessages
instance is
created, the error is added to the collection and the collection is set
under the Globals.ERROR_KEY
.
request
- The request we are handlingproperty
- The property name to use for this errorerror
- The error generated from the exception mappingforward
- The forward generated from the input path (from the
form or exception mapping)scope
- The scope of the exception mapping.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |