在我的web.xml上,我有这个:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.do</location>
</error-page>
<error-page>
<exception-type>org.apache.struts.chain.commands.UnauthorizedActionException</exception-type>
<location>/unauthorized.do</location>
</error-page>
问题是:当我遇到UnauthorizedActionException时,调用的操作是"error.do"(Throwable操作)。如果我评论了Throwable的,hhen我有一个UnauthorizedActionException,这个操作是可以的,但当我放Throwable时,它会进入错误的操作。有人能帮我吗?
UnauthorizedActionException
继承自java.lang.Throwable
,因此由您的第一个错误页面定义处理它是有效的。
尝试将定义重新排序为…
<error-page>
<exception-type>org.apache.struts.chain.commands.UnauthorizedActionException</exception-type>
<location>/unauthorized.do</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.do</location>
</error-page>
[编辑]关注您的评论
然后,我建议从web.xml中删除这些条目,并在struts-config.xml中配置异常处理程序。您可以在全局范围内定义异常处理程序。像这样的。。。
<global-results>
<result name="login" type="redirect">/Login.action</result>
<result name="Exception">/Exception.jsp</result>
<result name="UnauthorizedActionException">/UnauthorizedActionException.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="org.apache.struts.chain.commands.UnauthorizedActionException" result="UnauthorizedActionException"/>
<exception-mapping exception="java.lang.Exception" result="Exception"/>
</global-exception-mappings>