How to define a global page when requested page or method is not found?

♀尐吖头ヾ 提交于 2019-12-17 20:29:54

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/18503977/how-to-define-a-global-page-when-requested-page-or-method-is-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!