Struts 2.3表单带有多个提交标签和action属性

Rob*_*wen 7 forms jsp struts2 dmi

这非常简单,与Struts 2.1.x完美配合.但我们最近升级到2.3.15.2并且它破了.基本上我们有一个表单(实际上,很多表单)有多个提交:

<s:form>
 <s:submit action="save"  />
 <s:submit action="resetPassword"  />
</s:form>
Run Code Online (Sandbox Code Playgroud)

如果我坚持标签中的动作一切都很好.但如果它在标签中,我会收到404错误.这是同样的行动!

我一直在调试并发现当你在标签中使用"action"属性时,生成的html是:

<input type="submit" name="action:save">
<input type="submit" name="action:resetPassword">
Run Code Online (Sandbox Code Playgroud)

据说Struts应该采用这个"动作"前缀并说"A-ha!这是一个动作!" 并执行它.它或多或少都是这样.或至少尝试.我发现的是,在非常低的级别,DefaultActionMapper.handleSpecialParameters()方法遍历所有参数并尝试为每个参数创建一个ParameterAction,如果它不为null,则执行它.大多数参数产生"null"ParameterAction,但不产生"action:".

在文档中我发现了这个关于ParameterAction的内容:

Defines a parameter action prefix.  This is executed when the configured prefix key is
matched in a parameter name, allowing the implementation to manipulate the action mapping 
accordingly.  For example, if the "action:foo" parameter name was found, and a 
ParameterAction implementation was registered to handle the "action" prefix, the execute 
method would be called, allowing the implementation to set the "method" value on the 
ActionMapping
Run Code Online (Sandbox Code Playgroud)

所以它的作用是将映射的结果设置为一个新的ServletDispatcherResult,其名称为Action:

mapping.setResult(new ServletDispatcherResult(actionName));
Run Code Online (Sandbox Code Playgroud)

另一方面,当在s:form标记中指定动作时,映射的结果为null.

所以当我们最终到达Dispatcher.serviceAction()时:

if (mapping.getResult() != null) {
 Result result = mapping.getResult();
 result.execute(proxy.getInvocation());
} else {
 proxy.execute();
}
Run Code Online (Sandbox Code Playgroud)

因此,当在标记中指定操作时,将调用proxy.execute(),它只调用Action /方法本身.应该发生什么!但是当在标记中指定了动作时,由于映射具有结果,因此代理的调用将传递给result.execute(),它调用ServletDispatcherResult ...最后,我得到404.

这似乎是为了获得具有动作属性的多个提交按钮的大量工作.这是Struts 2.3的已知问题吗?我是否需要为文档中所述的"action"前缀实现ParameterAction?

编辑

好的,已知的bug,几天前刚刚开通.与此同时,我可以降级到2.3.15.1或使用"method"属性而不是"action"属性.

希望很快就会修好......

MSR*_*MSR 5

这是struts2.3.16中的b/c.

禁用对操作的支持:前缀

默认情况下 struts.mapper.action.prefix.enabled = false

<constant name="struts.mapper.action.prefix.enabled" value="true"/> 
Run Code Online (Sandbox Code Playgroud)

在struts.xml中

struts2-core 2.3.16的内部变化

操作:和方法:默认情况下排除前缀和更改顺序,首先检查excludeParams,然后在ParametersInterceptor中接受Acceptara


pla*_*147 2

2.3.15.3 应该正在修复此问题。

具体的jira是:

https://issues.apache.org/jira/browse/WW-4204