Java Struts中的Json插件和全局异常

Java Struts中的Json插件和全局异常,java,struts2,struts2-json-plugin,Java,Struts2,Struts2 Json Plugin,我试图返回一个JSON格式的全局异常。这是我目前使用的struts.xml。我不知道我错过了什么 <struts> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" value="global" /> <constant name="struts.configuration.xml.reload" value="tr

我试图返回一个JSON格式的全局异常。这是我目前使用的struts.xml。我不知道我错过了什么

<struts>

<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="global" />
<constant name="struts.configuration.xml.reload" value="true" />

<package name="mkaStrive" extends="json-default">
    <interceptors>
        <interceptor name="json" class="org.apache.struts2.json.JSONInterceptor" />
        <interceptor-stack name="mobileStack">
            <interceptor-ref name="json" />
            <interceptor-ref name="defaultStack" />
        </interceptor-stack>
    </interceptors>
    <default-interceptor-ref name="test" />

    <global-results>

        <!-- Exceptions are handled by ExceptionAction -->
        <result name="exception" type="chain">
            <param name="actionName">exception</param>
        </result>

    </global-results>

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

    <action name="exception" class="n.a.exception.ExceptionAction" />

    <action name="getQuestionsList" class="n.a.mkastrive.action.GetQuestions" method="execute">
        <interceptor-ref name="json" />
        <result type="json"></result>
    </action>       
</package>

理想情况下,从这里可以看到我有全局结果,然后链接到名为exception的操作。

我在您提供的
struts.xml
中看到的唯一问题是:(输入错误?)

使用

要获取从
GetQuestions.execute()
抛出的异常实例,可以在异常操作的
execute
方法中使用以下命令:

(异常)ActionContext.getContext().getValueStack().findValue(“异常”)


您可以对此进行操作,并在类中设置所需的私有字段,以便通过用于json呈现的公共getter获得这些字段。只是链接到for json响应。

谢谢,我会看看是否可以再试一次。但我转向了春天。
public String execute() throws Exception {
    throw new Exception("TEST");
}
<default-interceptor-ref name="mobileStack" />
<default-interceptor-ref name="test" />
<action name="exception" class="n.a.exception.ExceptionAction" >
  <result type="json"></result>
</action>