Struts2 struts.xml配置文件-定义全局配置项

Struts2 struts.xml配置文件-定义全局配置项,struts2,Struts2,在我的struts2应用程序中,我想定义一个全局配置部件,并在需要时使用它。 为了澄清,让我在下面分享一个行动定义 <action name="do_login" class="xxx.actions.AuthAction" method="doLogin"> <result name="success" type="json"> <param name="noCache">true</param>

在我的struts2应用程序中,我想定义一个全局配置部件,并在需要时使用它。 为了澄清,让我在下面分享一个行动定义

<action name="do_login" class="xxx.actions.AuthAction" method="doLogin">
        <result name="success" type="json">
            <param name="noCache">true</param>
            <param name="contentType">text/html</param>
            <param name="excludeProperties">actionErrors,actionMessages,errorMessages,errors,fieldErrors,locale,texts,action,username,password,errorCode,errorMessage,session</param>
            <param name="ignoreHierarchy">false</param>
        </result>

        <result name="error" type="json">
            <param name="noCache">true</param>
            <param name="contentType">text/html</param>
            <param name="excludeProperties">actionErrors,actionMessages,errorMessages,errors,fieldErrors,locale,texts,action,session</param>
            <param name="ignoreHierarchy">false</param>
        </result>
    </action>
正如您所看到的,在结果定义中,有一些重复的部分:

<param name="noCache">true</param>
<param name="contentType">text/html</param>
<param name="excludeProperties">actionErrors,actionMessages,errorMessages,errors,fieldErrors,locale,texts,action,username,password,errorCode,errorMessage,session</param>
<param name="ignoreHierarchy">false</param>
我想在struts.xml文件的开头全局定义这个重复部分,并在每个结果定义中使用它,如

<result name="success" type="json">
    {include global definition here}
</result>
我知道可以按包或操作拆分struts.xml,但我想知道是否可以按我的需要进行上述操作


对于任何响应,请提前发送thx。

Struts2没有全局参数,尽管它们有全局结果类型

因此,您可以很好地将成功和错误作为全局结果,并使用它们


它们有一个称为的东西,用于Action类,但不用于您需要的结果类型。

thx@mprabhat。在我的例子中,每个动作的成功或错误结果类型;即使大多数参数相同,参数也可能不同。因此,我认为我必须将struts.xml文件按不同的包或操作进行拆分。谢谢你的回答。@abanUlutaş是的,你可以这样做,你还应该考虑是否可以将它们分解成功能