我有一个数组ids_arr
,它是用一些值初始化的。
我必须传递这个数组并在 Action 类中检索它。
以下是我的代码:
脚本:
$.get('deleteProduct',
{
arr_ids_fm_ajax : ids_arr
},
function(jsonResponse){
alert(jsonResponse.msg);
}
);
}
Action 类:
public class ProductDetails extends ActionSupport {
int arr_ids_fm_ajax[];
public int[] getArr_ids_fm_ajax() {
return arr_ids_fm_ajax;
}
public void setArr_ids_fm_ajax(int[] arr_ids_fm_ajax) {
this.arr_ids_fm_ajax = arr_ids_fm_ajax;
}
public String deleteProduct() {
System.out.println(arr_ids_fm_ajax[0]); // here i want the values of my
// passed array from ajax.
return "success";
}
}
控制台错误:
Parameter [arr_ids_fm_ajax[]] didn't match acceptedPattern pattern!
请提供解决方案。感谢您提前回复。
最佳答案
像这样传递数组解决了问题。
data: $.param({
arr_ids_fm_ajax: ids_arr
}, true)
关于java - 使用 jquery 中的 ajax 请求将 javascript 数组传递给 struts 操作类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24721994/