Как использовать jQuery для публикации данных JSON в класс действий Struts2 ⇐ Jquery
-
Anonymous
Как использовать jQuery для публикации данных JSON в класс действий Struts2
I've a problem sending data from jQuery to struts2 action class. I have seen the question: JSON Jquery to Struts2 action but I don't understand the solution quite well.
Here is my problem:
The json array is like this:
[{"id":"1","code":"111","name":"ddd"}, {"id":"2","code":"222","name":"sss"}, {"id":"3","code":"333","name":"eee"}] I want to send the json data to the struts2 action class. The jQuery code is like this:
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 Chrome's Development Tool, I have seen the data submitted to the server side. But on the server side, I don't know how receive the json data.
Action:
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; } } In this way, data is null.
I've also tried to use a List to receive JSON data. Changing "data" type from String to List, it failed again. Probably because I don't quite understand the OGNL model which Struts2 is using.
Please Help Me. Thank you very much!
Источник: https://stackoverflow.com/questions/195 ... tion-class
I've a problem sending data from jQuery to struts2 action class. I have seen the question: JSON Jquery to Struts2 action but I don't understand the solution quite well.
Here is my problem:
The json array is like this:
[{"id":"1","code":"111","name":"ddd"}, {"id":"2","code":"222","name":"sss"}, {"id":"3","code":"333","name":"eee"}] I want to send the json data to the struts2 action class. The jQuery code is like this:
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 Chrome's Development Tool, I have seen the data submitted to the server side. But on the server side, I don't know how receive the json data.
Action:
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; } } In this way, data is null.
I've also tried to use a List to receive JSON data. Changing "data" type from String to List, it failed again. Probably because I don't quite understand the OGNL model which Struts2 is using.
Please Help Me. Thank you very much!
Источник: https://stackoverflow.com/questions/195 ... tion-class
Мобильная версия