起初我認爲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 serializationjquery
一:前臺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();
}
ajax