gpt4 book ai didi

exception-handling - 处理 web.xml 中的多个 定义

转载 作者:行者123 更新时间:2023-12-04 07:53:48 26 4
gpt4 key购买 nike

在我的 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 的,当我有一个 UnauthorizedActionException 时, Action 没问题,但是当我放置 throwable 时,它​​会执行错误的 Action 。谁能帮帮我?

最佳答案

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 和 configure your exception handlers in your 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>

关于exception-handling - 处理 web.xml 中的多个 <error-page> 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12159677/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com