jquery 向后台(Servlet)传递数组参数

前台代码:

        var mards = new Array();
	$("#messageTab tr:gt(0)").each(function(index, element) {							
            var mardid = trim($(this).find(":radio").val());		
            mards.push(mardid);						
        });	
        $.post(
              "mard.do?method=getDataByJson",
              //注意传参的方式
              {mards:mards},                
              function(){
                 alert('向后台发送JSON数据成功!');
              }
        );			


后台接收:

public ActionForward getDataByJson(ActionMapping map, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
                         String[] mards = request.getParameterValues("mards[]");      
         		 if(mards !=null){
				 for(String mard:mards){
					 System.out.println(mard);
				 }
			 }else{
				 System.out.println("获取数组参数失败!");
				 
				 
			 }
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
		
	}


注意: 后台要在参数名后面加上:[]

 

posted on 2012-07-27 16:30  babyblue  阅读(1564)  评论(1)    收藏  举报