I have a problem sending data from jQuery to the struts2 action class. I saw a question: JSON JQuery for a Struts2 action , but I don't understand the solution very well.
Here is my problem:
The json array looks like this:
[{"id":"1","code":"111","name":"ddd"}, {"id":"2","code":"222","name":"sss"}, {"id":"3","code":"333","name":"eee"}]
I want to send json data to struts2 action class. The jQuery code is as follows:
var data = JSON.stringify(dataObj); $.ajax({ url: "Update", type: "post", data: data, dataType: 'json', contentType:"application/json;charset=utf-8", success : function(){ alert("You made it!"); } });
However, in the Chrome Development Tool, I saw data submitted to the server. But on the server side, I don't know how to get json data.
Act:
public class Update extends ActionSupport{ private String data; public String getData(){ return data; } public void setData(String data){ this.data= data; } public String execute(){ System.out.println(data); return SUCCESS; } }
So data is null.
I also tried using List to get JSON data. Changing the data type from String to List<Node> , it again failed. Perhaps because I do not quite understand the OGNL model that Struts2 uses.
Please help me. Thank you very much!