【发布时间】:2014-09-26 14:05:15
【问题描述】:
我们已从 2.0 迁移到 2.3。在 Struts 2.0 中,我们能够发送包含 post 和 get 参数的 AJAX 请求。但是在迁移到 Struts 2.3 之后,却无法执行此类请求。
这是使用 Prototype.js 发出的示例 AJAX 请求的样子:
var url = '/security/userdetails.action?mode=edit&userid=5';
var params = Form.serialize(form);
new Ajax.Request(url,
{
parameters: params,
onSuccess: function(trans) {
console.debug('success', trans);
},
onFailure: function(trans) {
console.debug('failure', trans);
},
onException:function(trans) {
console.debug('exception', trans);
}
});
如您所见,上述 AJAX 请求同时包含 GET 和 POST 请求。这在 2.0 中运行良好,但在 2.3 中,似乎请求已验证并且请求被转发到结果类型“输入”,但为此我们没有配置 JSP,最后我们得到的只是 404 Not Found 错误。
但是如果我们将代码更改为以下代码,它也可以在 Struts 2.3 中运行
var url = '/security/userdetails.action?mode=edit'; // ------ The Changes are here
var params = Form.serialize(form);
params.userid = 5; // ----- And here
new Ajax.Request(url,
{
parameters: params,
onSuccess: function(trans) {
console.debug('success', trans);
},
onFailure: function(trans) {
console.debug('failure', trans);
},
onException:function(trans) {
console.debug('exception', trans);
}
});
第一种方法有什么问题? Struts 2.3 中是否有允许发出该请求的配置?
【问题讨论】:
-
尝试调试验证失败的参数并得到输入结果。这是因为 Struts 2.3 配置的可能性很小。
-
@Yogi 如果我只使用 url,'/security/userdetails.action?mode=edit&userid=5' 并且不包含 post 参数,它可以工作。他们两个(获取和发布)分别工作。但是作为一个整体,他们没有。顺便说一句,有什么方法可以让输入结果类型设置什么验证消息?
-
你的术语有点不对; Ajax 请求不“同时包含 GET 和 POST 请求”,它包含 URL 和请求正文中的参数。我不确定什么变化会影响到这一点,但是 S2.0 和 S2.3 之间的调度过程发生了很大变化。
标签: java ajax struts2 http-post url-parameters