【发布时间】:2015-09-09 09:25:19
【问题描述】:
我的意图是在 struts2 中将几个参数传递给一个动作,但我希望这些参数必须隐藏,因此不建议使用 GET 调用。我认为 jQuery 中的 post 或 ajax 调用可能是一个好主意,但是参数为 null 并且重定向到 jsp 页面不起作用。以下是操作和 javascript 代码:
MyAction.java
public class MyAction extends ActionSupport{
private Long pkId;
private String type;
public String execute() {
String pkId = getPkId();
String type = getType();
return Action.SUCCESS;
}
}
文件.js
function myFunction(){
var pkId = "pkId1";
var url = "./myAction.action";
var type = "type1";
$.ajax(url, {pkId : pkId, type : type});
}
更新代码:
function myFunction(){
var pkId = "pkId1";
var url = "./myAction.action";
var type = "type1";
$.post(url, {pkId : pkId, type : type}, function(resp){
// resp is the response from the server after the post request.
});
}
【问题讨论】:
-
您没有指定您想要
POST请求。$.ajax()调用的默认值为GET。按照文档中的说明指定method。
标签: javascript jquery struts2