在我的struts2應用程序中,我有要求將pojo列表發送到struts2動作。但無法獲得行動的方式。將json數組發送到使用Ajax的struts2動作
這是我的JavaScript函數。
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();
}
});
}
我Struts2的行動
public String testUrl()
{
//here what code i can use to get List of pojo
return SUCCESS;
}
當我運行此我警告get請求的值:
[{"xVal":"$3,000"},{"xVal":"$5,000"}]
我如何獲得Struts2的行動這個價值?
你可以打印你的輸出,因爲我有問題http://stackoverflow.com/questions/22062180/sending-array-from-jquery-to-servlet – haripcce