Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The above interceptors node configures a new stack of Struts 2 interceptors named appDefaultStack. This stack of interceptors is based upon the defaultStack of interceptors (which are the Struts 2 interceptors the that execute by default whenever an Action class method is called by the Struts 2 framework).

...

In the example applications, the logging is just to the Servlet container's console (see the log4j.xml file for the log settings).

...



   <action name="actionspecificexception" class="org.apache.struts.register.action.Register" method="throwSecurityException">
     <exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException" 
          result="login" />
      <result>/register.jsp</result>
      <result name="login">/login.jsp</result>
   </action>

The above action node from the example application's struts.xml file specifies that if method throwSecurityException throws an uncaught exception of type SecurityBreachException the Struts 2 framework should return a result of login. The login result will cause the user's browser to be redirected to login.jsp.

You can see that an action-specific exception mapping will take precedence if the same exception is also mapped globally.

Summary

Struts 2 provides a easy to use configuration for handling uncaught exceptions and redirecting users to appropriate view pages. You can configure exception handling to be global for all actions or to just for a specific action. You can also enable the Struts 2 framework to log the uncaught exceptions.

...