Struts全局异常映射给出通用HTTP错误500,而不是自定义异常结果

时间:2018-09-06 17:34:57

标签: exception-handling struts2 struts

我为具有名称空间struts.xml的特定软件包定义了/ws,以描述应用程序的Web服务部分:

<package name="app-ws" namespace="/ws" strict-method-invocation="false" extends="json-default">

    <interceptors>
        <interceptor name="wsInterceptor" class="myapp.WSInterceptor" />        
    </interceptors>

    <global-results>
        <result name="not.authorized">/WEB-INF/jsp/admin/not_authorized.jsp</result>
        <result name="exception">/WEB-INF/jsp/admin/exception.jsp</result>
    </global-results>       

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

    <action name="runWS" method="runWS" class="myapp.WSAction">
        <interceptor-ref name="wsInterceptor" />
    </action>           

</package>

然后在负责此操作的Java方法中(我已验证其工作原理),执行此操作:

public String runWS() throws Exception {

    throw new Exception("test");

}

我希望结果是我自定义的“异常”页面,因为我已经定义了(1)全局结果和(2)全局异常映射。

但是我明白了:

HTTP Status 500 – Internal Server Error
Type Exception Report

Message test

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

java.lang.Exception: test

为什么尽管有异常映射,我还是收到通用错误500?

0 个答案:

没有答案
相关问题