<small id='PMJ1V'></small><noframes id='PMJ1V'>

      <tfoot id='PMJ1V'></tfoot>

        • <bdo id='PMJ1V'></bdo><ul id='PMJ1V'></ul>

      1. <i id='PMJ1V'><tr id='PMJ1V'><dt id='PMJ1V'><q id='PMJ1V'><span id='PMJ1V'><b id='PMJ1V'><form id='PMJ1V'><ins id='PMJ1V'></ins><ul id='PMJ1V'></ul><sub id='PMJ1V'></sub></form><legend id='PMJ1V'></legend><bdo id='PMJ1V'><pre id='PMJ1V'><center id='PMJ1V'></center></pre></bdo></b><th id='PMJ1V'></th></span></q></dt></tr></i><div id='PMJ1V'><tfoot id='PMJ1V'></tfoot><dl id='PMJ1V'><fieldset id='PMJ1V'></fieldset></dl></div>
      2. <legend id='PMJ1V'><style id='PMJ1V'><dir id='PMJ1V'><q id='PMJ1V'></q></dir></style></legend>

        在 struts.xml 中声明/处理哪些异常

        时间:2023-10-15

        <small id='LN1ln'></small><noframes id='LN1ln'>

        • <tfoot id='LN1ln'></tfoot>
              <tbody id='LN1ln'></tbody>
            <i id='LN1ln'><tr id='LN1ln'><dt id='LN1ln'><q id='LN1ln'><span id='LN1ln'><b id='LN1ln'><form id='LN1ln'><ins id='LN1ln'></ins><ul id='LN1ln'></ul><sub id='LN1ln'></sub></form><legend id='LN1ln'></legend><bdo id='LN1ln'><pre id='LN1ln'><center id='LN1ln'></center></pre></bdo></b><th id='LN1ln'></th></span></q></dt></tr></i><div id='LN1ln'><tfoot id='LN1ln'></tfoot><dl id='LN1ln'><fieldset id='LN1ln'></fieldset></dl></div>
            <legend id='LN1ln'><style id='LN1ln'><dir id='LN1ln'><q id='LN1ln'></q></dir></style></legend>
                <bdo id='LN1ln'></bdo><ul id='LN1ln'></ul>

                1. 本文介绍了在 struts.xml 中声明/处理哪些异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Java中有CheckedUnchecked exceptions.

                  由于我是 Struts2 的新手,所以我对处理 checked exception 有一个愚蠢的疑问.我们编写try catch block来处理checked exceptions.因此,我们可以在 catch blockreturn view 页面的名称中编写返回语句,显示 Exception/Error.

                  I have one silly doubt regarding handling checked exception in mind as I am new to Struts2. We write try catch block to handle checked exceptions. So, we can write return statement in catch block and return view name of page which shows Exception/Error.

                  如果我抛出 struts.xml 文件中声明的 checked exception 并且结果是重定向到 Error/异常页面?

                  And what if I throw checked exception which is declared in struts.xml file and a result is a redirect to a Error/Exception page?

                  两者都是检查异常的正确方法吗?

                  推荐答案

                  应捕获应用程序级异常.如果你抛出一个应用程序级异常并且没有捕获它,它可能会被 exception 拦截器 如果它被配置为动作.

                  The application level exceptions should be caught. If you throw an application level exception and didn't catch it, it could be caught by the exception interceptor if it's configured to the action.

                  注意,异常拦截器位于 defaultStack 的底部,它不仅可以捕获动作中的异常,还可以捕获整个拦截器堆栈中的异常.如果您将此拦截器配置为映射应处理的异常并在其后返回结果,也应将其配置为全局结果,那么您的异常将被捕获并返回结果.如果您不这样做,Web 容器将处理该异常.正确的做法是捕获异常并返回错误结果,但如果做不到,则应配置异常拦截器.

                  Note, the exception interceptor is on bottom of the defaultStack that allows to catch exceptions not only in the action but in the whole stack of interceptors. If you configured this interceptor to map exceptions it should handle and result returned after it, which also should be configured as global results, then your exception will be caught and result returned. If you didn't, the web container will handle the exception. The right way is to catch exception and return an error result, but if you can't do it then you should configure exception interceptor.

                  注意,您的代码中发生的 Struts 容器异常不会由异常拦截器处理.在这种情况下,您应该捕获异常并将操作的状态设置为错误,然后您可以在操作执行中首先检查该状态以返回错误结果或抛出可能被代码中的异常拦截器捕获的异常不能返回错误结果的地方.您可以在文档中找到有关异常配置的更多信息.

                  Note, that Struts container exceptions occurred in your code aren't handled by the exception interceptor. In this case you should catch the exception and set the state of the action to error and after that you can check that state first in the action execution to return an error result or throw an exception that could be caught by the exception interceptor in the code where you can't return an error result. More about exception configuration you can find in the documentation.

                  这篇关于在 struts.xml 中声明/处理哪些异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 &lt;s:if&gt;Struts 2 中的标签? 下一篇:使用 DisplayTag 库框架通过 Struts2 进行分页

                  相关文章

                  1. <small id='z2LJn'></small><noframes id='z2LJn'>

                      <i id='z2LJn'><tr id='z2LJn'><dt id='z2LJn'><q id='z2LJn'><span id='z2LJn'><b id='z2LJn'><form id='z2LJn'><ins id='z2LJn'></ins><ul id='z2LJn'></ul><sub id='z2LJn'></sub></form><legend id='z2LJn'></legend><bdo id='z2LJn'><pre id='z2LJn'><center id='z2LJn'></center></pre></bdo></b><th id='z2LJn'></th></span></q></dt></tr></i><div id='z2LJn'><tfoot id='z2LJn'></tfoot><dl id='z2LJn'><fieldset id='z2LJn'></fieldset></dl></div>
                    1. <tfoot id='z2LJn'></tfoot>
                      • <bdo id='z2LJn'></bdo><ul id='z2LJn'></ul>
                    2. <legend id='z2LJn'><style id='z2LJn'><dir id='z2LJn'><q id='z2LJn'></q></dir></style></legend>