出自:http://blog.csdn.net/ojackhao/article/details/24580437
起初我认为traditional:true,可有可无,但是后来不用traditional的时候,发现后台无法获取selectUsers的值,那么可以肯定的是traditional默认值是false.
当提交的参数是数组( {selectUsers:[value,value,value]} ),如果是false的话,则提交时会是"selectUsers[]=value&selectUsers[]=value"
如果设置成true,则提交时会是"selectUsers=value&selectUsers=value"
这样后台就能用String[] ids=request.getParameterValues("selectUsers"); 获取到值。
官方文档的解释如下:
traditional
类型:Boolean
如果你想要用传统的方式来序列化数据,那么就设置为 true。
Set this to true if you wish to use the traditional style of param serialization
一:前台jQuery
deleteAll() {
var selectUsers=new Array();
//var selectUsers = null;
$(":checkbox[name=‘userID‘]").each(function() {
if ($(this).attr("checked"))
selectUsers.push($(this).val());
//selectUsers += "," + $(this).val();
})
//alert(selectUsers);
$.ajax({
//async : false,
traditional: true,
type:"post",
url:"elecUserAction_delete.do",
data:{selectUsers:selectUsers},
/* success:function(responsText){
if(responsText=="1"){
alert("删除成功");
}
} */
});
}
二:后台Action代码
public String delete(){
//ActionContext context=ActionContext.getContext();
//HttpServletRequest request=(HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
String[] ids=request.getParameterValues("selectUsers");
System.out.println(ids.toString());
PrintWriter out = null;
out.write("1");
return home();
}