My intent is to pass a couple of parameters to an action in struts2, but I want that these parameters have to be hidden, so the GET call is not recommended. I thought that a post or ajax call in jQuery could be a good idea to do so, but the parameters are null and the redirect to the jsp page doesn't work. Here are the Action and the javascript codes:
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;
}
}
file.js
function myFunction(){
var pkId = "pkId1";
var url = "./myAction.action";
var type = "type1";
$.ajax(url, {pkId : pkId, type : type});
}
Updated code:
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.
});
}