Exception handling 处理多个<;错误页面>;web.xml中的定义

Exception handling 处理多个<;错误页面>;web.xml中的定义,exception-handling,error-handling,struts,web.xml,Exception Handling,Error Handling,Struts,Web.xml,在我的web.xml上,我有以下内容: <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/error.do</location> </error-page> <error-page> <exception-type>org.apa

在我的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>  

java.lang.Throwable
/error.do
org.apache.struts.chain.commands.UnauthorizedActionException
/你呢
问题是:当我有一个UnauthorizedActionException时,调用的操作是“error.do”(可丢弃的操作)。 如果我对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>  

org.apache.struts.chain.commands.UnauthorizedActionException
/你呢
java.lang.Throwable
/error.do
[编辑]在您的评论之后

然后,我建议将这些条目从web.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>

/Login.action
/Exception.jsp
/UnauthorizedActionException.jsp

我也遇到了同样的情况。如果我删除了Throwable的声明,那么它对我的另一个异常有效,否则它将重定向到Throwable时代。无论声明的顺序如何。