2

I know how to fine a global error redirect page in our defined package when exception encountered that just by adding the following configuration in the parent package in struts.xml:

<global-results>
    <result name="error">/error.jsp</result>
</global-results>

<global-exception-mappings>
    <exception-mapping exception="java.lang.Exception" result="error" />
</global-exception-mappings>

But It seems to not able to catch those exceptions like requested resources, methods, pages are not found, I mean how to catch the struts2-level errors, and then I can do something to handle it.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Brady Zhu
  • 1,305
  • 5
  • 21
  • 43

2 Answers2

2

You should define your unknown handler in the struts.xml. Unknown handlers are called by the framework, when an unknown action, result, or method are executed.

<bean type="com.opensymphony.xwork2.UnknownHandler" name="handler" class="com.package.SomeUnknownHandler"/> 

The class should implement UknownHandler interface to handle the cases:

  • when an action configuration is unknown
  • when a result cannot be found for an action and result code
  • when an action method cannot be found
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • 1
    Thanks for pointing me a mind. And now the question I get is how should I implement the UnknownHandler interface, what logic should I do? throw a exception, or return the related object for redirect the URL I handle it?? – Brady Zhu Aug 29 '13 at 09:36
  • It's up to you, actions usually redirect to known action, results to known result, method to known method. – Roman C Aug 29 '13 at 10:19
  • 1
    Ok, Thanks. UknownHandler is exactly provides us a interface to catch these unknown cases and do the appropriate handlings, right? – Brady Zhu Aug 30 '13 at 01:19
0

Here some detaiks a how you can use the UknownHandler (https://stackoverflow.com/a/27881698/3383543), enjoy.

Community
  • 1
  • 1
Ahmad AlMughrabi
  • 1,612
  • 17
  • 28