In my struts2 application, I have requirement to send list of pojo to struts2 action. But unable to get the way to get that on action.
Here is my JavaScript function.
function go() {
var requests = Array();
var url='testUrl';
$('.innertable').each(function(index){
var form= $(this).closest('form');
if(index!=0)
{
var xVal=form.find("#xVal"+index).val();
}
else
{
var xVal=form.find("#xVal"+index).val();
}
var testPojo = {
xVal:xVal
}
requests.push(testPojo);
});
alert('======='+JSON.stringify(requests));
$.ajax({
url: url,
data: JSON.stringify(requests),
contentType: "application/json; charset=utf-8",
type: 'POST',
success: function(data){
//success code
},
error: function(xhr, status, error) {
alert(xhr.responseText);
window.location.reload();
}
});
}
My struts2 action
public String testUrl()
{
//here what code i can use to get List of pojo
return SUCCESS;
}
When I run this I get request's value in alert:
[{"xVal":"$3,000"},{"xVal":"$5,000"}]
How can I get this value in struts2 action?