将数组值从js文件传递到JSP文件

时间:2014-09-03 07:10:18

标签: java javascript arrays jsp

js file:
  通过dropdown1 [i]时,只有一个元素通过。但是kot [i],item [i]完全通过了。

for(var i=0;i<count;i++)
{
    dropdown1[i]=document.getElementById("sel"+i).value;
    kot[i]=document.getElementById("kot"+i).value;
    item[i]=document.getElementById("itemcode"+i).value;
    if(dropdown1[i] == 0){
        document.detailsview.action="BillCB.jsp?method=" + "11" + "&itemcode=" +item[i]+ "&kot=" +kot[i]+ "&itemStatus1=" +dropdown1[i]+ "&billno=" +billno;
    }
    else if(dropdown1[i] == 1){
        document.detailsview.action="BillCB.jsp?method="+"9"+"&itemcode="+item[i]+"&kot="+kot[i]+"&itemStatus1="+dropdown1[i]+ "&billno="+billno;
    }
    else{
        document.detailsview.action= "BillCB.jsp?method="+"10"+"&itemcode="+item[i]+"&kot="+kot[i]+"&itemStatus1="+dropdown1[i]+ "&billno="+billno;
    }
}

JSP文件:

 case 11:
 gotMethod = true;
 billdetails_be.billno = Integer.valueOf(request.getParameter("billno"));
 String[] kotCB2=request.getParameterValues("kot");
 String[] itemCB2=request.getParameterValues("itemcode");
 String[] statCB2=request.getParameterValues("itemStatus1");
 int[] kotarr2=new int[kotCB2.length];
 int[] itemarr2=new int[itemCB2.length];
 int[] statarr2=new int[statCB2.length];
 System.out.println("IN AVAILABLE:length of array is:"+statCB2.length);
 System.out.println("IN AVAILABLE:length of array is:"+kotCB2.length);
 for(int i=1;i<itemarr2.length;i++)
 {   
     kotarr2[i]=Integer.parseInt(kotCB2[i]);
 }
 for(int i=1;i<itemarr2.length;i++)
 {  
     itemarr2[i]=Integer.parseInt(itemCB2[i]);
 }
 for(int i=1;i<itemarr2.length;i++)
 { 
     statarr2[i]=Integer.parseInt(statCB2[i]);  
 }
 for(int i=1;i<itemarr2.length;i++)
 {
     int kotint2=kotarr2[i];
     int itemint2=itemarr2[i];
     int statint2=statarr2[i];
     System.out.println( i+"the value of kot in available"+ kotint2);
     int availablebill = websrv.availablebill(billdetails_be.billno, kotint2, itemint2,statint2);   
 }

1 个答案:

答案 0 :(得分:0)

JS:

for(var i=0;i<count;i++)
{
    dropdown1[i]=document.getElementById("sel"+i).value;
    kot[i]=document.getElementById("kot"+i).value;
    item[i]=document.getElementById("itemcode"+i).value;
    if(dropdown1[i] == 0){
        document.detailsview.action="BillCB.jsp?method=" + "11" + "&itemcode=" +JSON.stringify(item)+"&kot="+JSON.stringify(kot)+"&itemStatus1="+JSON.stringify(dropdown1)+ "&billno=" +billno;
    }
    else if(dropdown1[i] == 1){
        document.detailsview.action="BillCB.jsp?method="+"9"+"&itemcode="+JSON.stringify(item)+"&kot="+JSON.stringify(kot)+"&itemStatus1="+JSON.stringify(dropdown1)+ "&billno="+billno;
    }
    else{
        document.detailsview.action= "BillCB.jsp?method="+"10"+"&itemcode="+JSON.stringify(item)+"&kot="+JSON.stringify(kot)+"&itemStatus1="+JSON.stringify(dropdown1)+ "&billno="+billno;
    }
}

JSP文件:

JSONParser parser=new JSONParser();
Object obj = parser.parse(request.getParamete("kot"));
JSONArray JSonkot = (JSONArray)obj;