如何在 Struts 2 中捕获默认拦截器堆栈抛出的异常? [英] How to catch the exception thrown by default interceptor's stack in Struts 2?

查看:23
本文介绍了如何在 Struts 2 中捕获默认拦截器堆栈抛出的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Struts 2中如何捕捉默认拦截器堆栈抛出的异常?

How to catch the exception thrown by default interceptor's stack in Struts 2?

异常消息:

There is no action mapped for action name `index`. 

如何捕获异常,因为我想定义我的处理方式?

How to catch the exception, because I want to define my handling?

com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter.doFilter(StrutsPrepareFilter.java:82)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    com.zhanxiao.sys.PermissionFilter.doFilter(PermissionFilter.java:61)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.proces

推荐答案

由于请求使用的 URL 未正确映射到操作配置而引发异常.要消除异常,您应该正确地将 URL 映射到操作或使用默认操作引用,如果没有找到给定 URL 的操作,则会调用该引用.

The exception is thrown because URL used with the request is not properly mapped to the action configuration. To get rid of the exception you should properly map URL to the action or use default action reference which will be called if no action found for the given URL.

您也可以使用通配符映射来映射一堆 URL,即使使用正则表达式模式匹配器也会找到您的操作,或者如果通过提供您的自定义实现来覆盖操作映射器的默认行为没有帮助.

You may also use wildcard mapping to map a bunch of URLs even with regex pattern matcher which will find your action or if it doesn't help to override the default behavior of the action mapper by supplying your custom implementation.

要处理来自您的操作代码和拦截器堆栈的异常,您可以使用 <代码>异常拦截器在你的动作堆栈上.它将通过全局异常映射帮助您处理什么样的异常,并定义实际处理异常的全局结果.请参阅链接,其中详细解释了如何使用异常处理制作默认包的详细信息和示例.

To handle exceptions form your action code and interceptor's stack you can use the exception interceptor on the stack of your action. It will help you what kind of exceptions you want to handle via global exception mapping and define the global results that will actually handle the exception. See the link that explains more in details and examples how to make the default package with exception handling.

有一个选项可以扩展拦截器并覆盖文档中也描述的异常处理机制.

There's an option to extend the interceptor and override the exception handling mechanism as also described in the docs.

这篇关于如何在 Struts 2 中捕获默认拦截器堆栈抛出的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆