gpt4 book ai didi

forms - Struts 2.3 表单,带有多个带有 action 属性的提交标签

转载 作者:行者123 更新时间:2023-12-04 11:53:49 24 4
gpt4 key购买 nike

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

<s:form>
<s:submit action="save" />
<s:submit action="resetPassword" />
</s:form>

如果我把 Action 贴在标签中,一切都很好。但是如果它在标签中,我会收到 404 错误。而且是一样的 Action !

我一直在调试,发现当你在标签中使用“action”属性时,生成的html是:
<input type="submit" name="action:save">
<input type="submit" name="action:resetPassword">

据说 Struts 应该使用这个“ Action ”前缀并说“啊哈!这是一个 Action !”并执行它。它或多或少是这样做的。或者至少尝试这样做。我发现在非常低的级别, DefaultActionMapper.handleSpecialParameters() 方法遍历所有参数并尝试为每个参数创建一个 ParameterAction,如果它不为空,则执行它。大多数参数产生“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

所以它所做的是将映射的结果设置为一个带有 Action 名称的新 ServletDispatcherResult:
mapping.setResult(new ServletDispatcherResult(actionName));

另一方面,当在 s:form 标记中指定操作时,映射的结果为空。

所以当我们最终到达 Dispatcher.serviceAction() 时:
if (mapping.getResult() != null) {
Result result = mapping.getResult();
result.execute(proxy.getInvocation());
} else {
proxy.execute();
}

所以当在标签中指定 Action 时,proxy.execute() 被调用,它只是调用 Action /方法本身。这是应该发生的事情!但是当在标签中指定 Action 时,由于映射有结果,代理的调用被传递给 result.execute(),它调用 ServletDispatcherResult ... 最后,我得到一个 404。

这似乎需要做很多工作才能获得多个具有操作属性的提交按钮。这是 Struts 2.3 的已知问题吗?我是否需要为文档中所述的“action”前缀实现 ParameterAction ?

编辑

好的,已知错误,几天前才打开。同时,我可以降级到 2.3.15.1 或使用“method”属性而不是“action”属性。

希望它会尽快修复...

最佳答案

这是 struts2.3.16 中的 b/c。

禁用对操作的支持:前缀

默认 struts.mapper.action.prefix.enabled = false

<constant name="struts.mapper.action.prefix.enabled" value="true"/> 

在 struts.xml 中

struts2-core 2.3.16 内部变化

action: 和 method: 前缀默认被排除并更改顺序以首先检查 excludeParams 然后在 ParametersInterceptor 中检查 acceptParams

关于forms - Struts 2.3 表单,带有多个带有 action 属性的提交标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19136863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com