Ajax 传递数组到后台

function login123(){
		var nameArr = new Array();
		nameArr.push("adm,in");
		nameArr.push("jo,in");
		nameArr.push("check,in");
		console.info(nameArr);
		$.ajax({
			url:contPath+"/login.htm",
			//data:{"names":nameArr},
			data:{"names[]":nameArr},
			type:"post",
			success:function(data){
				alert("success");
			}
		});
	}
@RequestMapping("login")
	public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {


System.out.println(request.getParameter("names"));

//注意这里 HttpServletRequest默认加了 []  不管 js中加不 加 [] 
System.out.println(request.getParameterValues("names[]").length);
		System.out.println(Arrays.toString(request.getParameterValues("names[]")));
		System.out.println(request.getParameterValues("names[]").getClass());

}

//参考文章如下

http://www.jb51.net/article/40131.htm

相关推荐