struts2中的全局异常

时间:2010-07-27 13:08:44

标签: struts2

我正在尝试在struts.xml中配置全局异常。当我包含全局异常映射标记时,项目没有开始。我在日志中收到以下消息,

Jul 27, 2010 6:33:07 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Jul 27, 2010 6:33:07 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/ehspreg2] startup failed due to previous errors
log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository.

Struts.xml文件是,

<package name="default" extends="struts-default">

        <result-types>
            <result-type name="tiles"
                class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>

        <interceptors>
            <interceptor-stack name="ehspre2stack">
                <interceptor-ref name="paramsPrepareParamsStack">
                    <param name="validation.excludeMethods">
                        list,loadedit,remove,execute,reset
                    </param>
                    <param name="exception.logEnabled">true</param>
                    <param name="exception.logLevel">ERROR</param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>


        <default-interceptor-ref name="ehspre2stack" />

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

        <global-results>
            <result name="exception">jsp/common/error.jsp</result>
        </global-results>


        <action name="home">
            <result type="tiles" name="success">showHome</result>
        </action>

        <action name="login"
            class="com.mmm.ehspreg2.web.action.WelcomeAction">
            <result type="tiles" name="local">showLogin</result>
        </action>
</package>

1 个答案:

答案 0 :(得分:4)

根据struts.xml dtd<global-exception-mappings>之后需要定义<global-results>

    <global-results>
        <result name="exception">jsp/common/error.jsp</result>
    </global-results>

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