如何在 Struts 2 中使用整个通配符值作为重定向结果

How to use the entire wildcard value as a redirect result in Struts 2

我想知道如何使用 Struts2 通配符功能根据 return 值将用户重定向到另一个操作:

struts.xml:

<action name="menu" class="a.b.c.d.e.f.actions.SecureMenuAction" method="prompt" >
    <result name="success" type="tiles">.clf.sm</result>
    <result name="input" type="tiles">.clf.smLevel3</result>
    <result name="*" type="redirectAction">{1}</result>
</action>

操作:

String redirectString;
// --- code --- \
return redirectString;

在某些情况下,return 结果 SUCCESSINPUT 是有效的,但在所有其他情况下,我希望使用 return 的确切字符串作为重定向位置。

如果我将 struts.xml 替换为:

<result name="test*" type="redirectAction">{1}</result>

然后 {1} 将替换为 test,然后是我希望用户定向到的正确操作。

但是,如果我简单地使用 * 作为我的结果名称,那么它根本不会替换 {1}(好像不能这样使用通配符功能一样)。


有谁知道我可以使用 Struts2 (2.3.16.2) 中可用的方法使它工作的方法吗?

结果名称 "*" 不是 通配符。对于 other 结果名称有特殊含义,如果没有匹配的结果名称,则采用该结果名称。

如果你想重定向动作,那么你应该为动作名称提供一个 getter 并在结果配置中使用动态参数。

<action name="menu" class="a.b.c.d.e.f.actions.SecureMenuAction" method="prompt" >
    <result name="success" type="tiles">.clf.sm</result>
    <result name="input" type="tiles">.clf.smLevel3</result>
    <result name="*" type="redirectAction">${redirectString}</result>
</action>