0

我正在尝试扩展 ExceptionMappingInterceptor。我创建了一个覆盖 ExceptionMappingInterceptor 的 publishException(...) 方法的侦听器。但它不会监听应用程序中未处理的任何全局异常。

这是我的配置。

//处理程序

public class GlobalExceptionHandler extends ExceptionMappingInterceptor 
{
    private Logger logger = AppLogger.getLogger(this.getClass());

    @Override
    protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder) 
    {
        logger.error("Global Exception msg: "+ exceptionHolder.getException().getMessage(), exceptionHolder.getException());
        super.publishException(invocation, exceptionHolder);
    }
}

在 struts.xml 中

<interceptors>
     <interceptor name="sessionInterceptor" class="com.jak.session.SessionInterceptor" />
     <interceptor name="exception" class="com.jak.exception.GlobalExceptionHandler" />
     <interceptor-stack name="mymatrixxInterceptorStack">
        <interceptor-ref name="exception"></interceptor-ref>
        <interceptor-ref name="defaultStack"></interceptor-ref>
        <interceptor-ref name="sessionInterceptor"/>
     </interceptor-stack>
</interceptors>

<global-results>
    <result name="exception" type="tiles">myAccount</result>
</global-results>

<global-exception-mappings>
    <exception-mapping exception="java.lang.Exception" result="exception" />
</global-exception-mappings>

<action name="myAccount">
     <interceptor-ref name="mymatrixxInterceptorStack"></interceptor-ref>
     <result type="tiles">errorPage</result>
</action>

在上传文件时,我遇到了一个异常“没有为操作 com.dsdar.business.offer.CampaignUpdateAction 和结果输入定义结果”。但是这个拦截器不处理这个异常。我不知道它不听的原因。

4

1 回答 1

0

在 struts.xml 中

 <interceptors>
 <interceptor name="sessionInterceptor" class="com.jak.session.SessionInterceptor" />
        <interceptor name="exception"
            class="com.jak.exception.GlobalExceptionHandler" />
        <interceptor-stack name="mymatrixxInterceptorStack">
            <interceptor-ref name="exception"></interceptor-ref>
            <!--<interceptor-ref name="defaultStack"></interceptor-ref>--><!-- Here!! -->

            <interceptor-ref name="myDefaultStack"></interceptor-ref><!--  Here!!  -->

            <interceptor-ref name="sessionInterceptor" />
        </interceptor-stack>

        <interceptor-stack name="myDefaultStack">

            <!-- <interceptor-ref name="exception"/> --><!-- Here!! -->

            <interceptor-ref name="alias" />
            <interceptor-ref name="servletConfig" />
            <interceptor-ref name="i18n" />
            <interceptor-ref name="prepare" />
            <interceptor-ref name="chain" />
            <interceptor-ref name="debugging" />
            <interceptor-ref name="scopedModelDriven" />
            <interceptor-ref name="modelDriven" />
            <interceptor-ref name="fileUpload" />
            <interceptor-ref name="checkbox" />
            <interceptor-ref name="multiselect" />
            <interceptor-ref name="staticParams" />
            <interceptor-ref name="actionMappingParams" />
            <interceptor-ref name="params">
                <param name="excludeParams">dojo\..*,^struts\..*</param>
            </interceptor-ref>
            <interceptor-ref name="conversionError" />
            <interceptor-ref name="validation">
                <param name="excludeMethods">input,back,cancel,browse</param>
            </interceptor-ref>
            <interceptor-ref name="workflow">
                <param name="excludeMethods">input,back,cancel,browse</param>
            </interceptor-ref>
        </interceptor-stack>

    </interceptors>

    <global-results>
        <result name="exception" type="tiles">myAccount</result>
    </global-results>

    <global-exception-mappings>
        <exception-mapping exception="java.lang.Exception"
            result="exception" />
    </global-exception-mappings>

    <action name="myAccount">
        <interceptor-ref name="mymatrixxInterceptorStack"></interceptor-ref>
        <result type="tiles">errorPage</result>
    </action>

我不懂英语。原因是,请教别人。(>_<)

于 2012-06-06T06:10:04.233 回答