<pre name="code" class="java">String mapJson=request.getParameter("map");
JSONObject jb = JSONObject.fromObject(mapJson);
Map map=(Map)jb;
System.out.print(map);
var map={};var custom=$("#customproduct").val();for(var i=0;i<custom;i++){ var str="name"+i;var str1=$("#"+str).val();var str2="value"+i;var str3=$("#"+str2).val();alert(str1+ str3);map[str1]=str3;}var mapJson=JSON.stringify(map);
<span style="font-size:24px;color:#ff6666;">首先动态获取输入框中的值,将数组对象封装为json</span>
$.post('../Product_release',{
<span style="white-space:pre"> </span>"map":mapJson
},function (data){
<span style="white-space:pre"> </span>if(data.state == "success"){
<span style="white-space:pre"> </span>alert("添加成功");
<span style="white-space:pre"> </span>window.location.reload();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>});
<span style="font-size:32px;color:#ff6666;">接着用ajax传递给后台action</span>
<span style="color: rgb(255, 102, 102);"><span style="font-size:18px;">
</span></span>
<pre name="code" class="java"><span style="font-size:18px;">String mapJson=request.getParameter("map");
JSONObject jb = JSONObject.fromObject(mapJson);
Map map=(Map)jb;
System.out.print(map);</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">后台取得后转为Map对象~</span>