Hi I am trying to pass an array to Struts2 action class using jquery's getJSON() method but everytime its passing null elements.
var userIds=[];
Then populating UserIds array with push() method:
$.getJSON('abc.action',{userArray:userIds}, function(json) {
for(var i=0;i<json.returnMessages.length;i++){
alert(json.returnMessages[i]);
}
});
Also , in the action class should i use array or arraylist will work as receiver variable. Please suggest ! Help is appreciated.
Server-Side code:
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.Action;
public class UserDetails {
private static final long serialVersionUID = 1L;
String[] userArray = new String[2];
private List<String> returnMessages = new ArrayList<String>();
public String[] getuserArray() {
return userArray;
}
public void setuserArray(String[] userArray) {
this.userArray = userArray;
}
public void setReturnMessages(List<String> returnMessages) {
this.returnMessages = returnMessages;
}
public List<String> getReturnMessages() {
return returnMessages;
}
public String execute() {
try
{
for (int i = 0; i < userArray.length; i++) {
System.out.println("Success");
returnMessages.add("Success");
}
}
catch (Exception e)
{
e.printStackTrace();
}
return Action.SUCCESS;
}
}