Java 重定向动作中的 Struts2 动态参数名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1313121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 08:07:42  来源:igfitidea点击:

Struts2 dynamic parameter name in redirect-action

javaurlredirectstruts2

提问by fmpdmb

I'm successfully using a redirect-action for one of my struts2 mapping files as follows:

我成功地为我的 struts2 映射文件之一使用了重定向操作,如下所示:

<action name="setAsCurrentCart" class="com.fmp.MyAction">
  <result name="success" type="redirect-action">
    <param name="actionName">myOtherAction</param>
    <param name="foo">${foo}</param>
  </result>
  <interceptor-ref name="defaultComponentStack"/>
</action>

Here's what I want to do though:

不过,这就是我想要做的:

<action name="setAsCurrentCart" class="com.fmp.MyAction">
  <result name="success" type="redirect-action">
    <param name="actionName">myOtherAction</param>
    <param name="${dynamicParameterName}">${dynamicParameterValue}</param>
  </result>
  <interceptor-ref name="defaultComponentStack"/>
</action>

In other words, I want the name of the parameter that I'm passing to be dynamic. Does anyone know if this is possible?

换句话说,我希望我传递的参数的名称是动态的。有谁知道这是否可能?

采纳答案by fmpdmb

Actually, that doesn't work. However, I was able to get this working doing the following:

实际上,这行不通。但是,我能够执行以下操作:

<action name="setAsCurrentCart" class="com.fmp.MyAction">
   <result name="success" type="redirect-action">
      <param name="actionName">myOtherAction</param>
      <param name="${dynamicParameterName}">${dynamicParameterValue}</param>
   </result>
</action>

I had just assumed it wouldn't work.

我只是认为它行不通。

回答by Brad Cupit

could you do this instead?

你可以这样做吗?

<action name="setAsCurrentCart" class="com.fmp.MyAction">
   <result name="success" type="redirect-action">
      <param name="actionName">myOtherAction</param>
      <param name="paramName">${dynamicParameterName}</param>
      <param name="paramValue">${dynamicParameterValue}</param>
   </result>
</action>