Stack Exchange
Array Index out of bound in jsp file
js file: 

why does the size of dropdown1 is coming as 1?

function savethechanges(){
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 file:

while retrieving here the dropdown1 length is 1.but for kot and item length is 18
  please provide your solution!

 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); 
  }

design page(jsp)
<%
for(int i=0;i<count;i++){
%>
<TR>
<TD>  <input id="itemcode<%=i%>" type="hidden" name="itemcode" value=" <%=billdetails_be.get(i).itemcode%>"></TD>
<TD><%=billdetails_be.get(i).itemdescription%></TD>
<TD>&nbsp;&nbsp;<input id="quantity<%=i%>" type="text" name="quantity"  style="width:  30px;" readOnly="readonly" value="<%=billdetails_be.get(i).quantity%>" >
<input type="submit"  id="inc<%=i%>" onclick= "doIt1(1,<%=i%>);"  value="+" style="width:20px; height:20px; border-radius:10px; padding:0 0; " /> 
<input type="submit"  id="dec<%=i%>" onclick="doIt1(-1,<%=i%>);"   value="-" style="width:20px; height:20px; border-radius:10px; padding:0 0; "/>
</TD>
<TD>&nbsp;&nbsp;<%=billdetails_be.get(i).price%></TD>
<TD>&nbsp;&nbsp;<%=billdetails_be.get(i).itemstatusdescription%></TD>
<td>
<select name="statusi" id="sel<%=i%>">
<option value="0">Available</option>
<option value="1">Unavailable</option>
<option value="2">Delete</option>
</select> 
</td>               
<td> <input id ="kot<%=i%>" type="text" style="border: 0px solid #000000;" name="kot"   style="cursor: text" readonly="readonly" value="<%=billdetails_be.get(i).kotno%>"></td>         
<TD> <input id="myquantity<%=i%>" type="hidden" name="quantity1" value="     <%=billdetails_be.get(i).quantity%>"></TD>
</TR> 
<%
} 
%>
<td><input style="width: 150px; " class="btn btn-green btn-large" type="submit" name="save" id="save" value="save"  class="button" onclick="savetheChanges(<%=count%>);">    </td>

New changes

1.this is in js file ,from which i am passing the value to BillCB.jsp

 document.detailsview.action="BillCB.jsp?method=" + "11" + "&itemcode=" +itemcode1[i]+ "&kot=" +kot1[i]+ "&itemStatus1=" +selection[i]+ "&billno=" +billno;


2.this is in BillCB.jsp file (method :11)

 String[] statCB2=request.getParameterValues("itemStatus1");
 int[] statarr2=new int[statCB2.length];
 System.out.println("IN AVAILABLE:length of STATUS array is:"+statCB2.length);


In AVAILABLE:length of STATUS array is:1-this is the problem.


Please provide more information, such as the actual markup for the elements with ids "sel"+i, "kot"+i and "itemcode"+i ...  Its not clear where these are coming from


First, it is a little bit strange that in all your loops you are looping through itemarr2, so i do not understand why don't you have only one loop with all the logic inside.
Secondly you are looping through itemarr2 and then using the current index of itemarr2 to access and assign values in other arrays. If  any of this arrays has a smaller size than itemarr2 you will get an array indexOutofbound exception.
for(int i=1;i<itemarr2.length;i++)
{   
   kotarr2[i]=Integer.parseInt(kotCB2[i]); //If size of itemarr2 is bigger than kotarr2 or is bigger than kotCB2. You will get an array indexOutofbound exception.
}
for(int i=1;i<itemarr2.length;i++)
{  
   itemarr2[i]=Integer.parseInt(itemCB2[i]); //If size of itemarr2 is bigger than itemCB2. You will get an array indexOutofbound exception.
}
for(int i=1;i<itemarr2.length;i++)
{ 
   statarr2[i]=Integer.parseInt(statCB2[i]);  //If size of itemarr2 is bigger than statarr2 or is bigger than statCB2. You will get an array indexOutofbound exception.  
}
for(int i=1;i<itemarr2.length;i++)
{
  int kotint2=kotarr2[i];  //If size of itemarr2 is bigger than kotarr2. You will get an array indexOutofbound exception.
  int itemint2=itemarr2[i]; //If size of itemarr2 is bigger than itemarr2. You will get an array indexOutofbound exception.
  int statint2=statarr2[i]; //If size of itemarr2 is bigger than statarr2. You will get an array indexOutofbound exception.
  System.out.println( i+"the value of kot in available"+ kotint2);
  int availablebill = websrv.availablebill(billdetails_be.billno, kotint2, itemint2,statint2); 
}


So you must ensure that the size of kotarr2, kotCB2, itemCB2, statarr2, statCB2 is always bigger or equal to the size of itemarr2, and as i said you can pul all that logic insdide of a single loop.
Regarding your Js file we need to see how you set your count, but if the value of your count is bigger than the size of your dropdown1 then You will get an array indexOutofbound exception.
UPDATE: 
You said that count = 18, but you do not initialize statarr2 using count. You initialize it using statCB2.length.
     int[] statarr2=new int[statCB2.length];

In turn statCB2.length is also not initialized using count it is initialized using request.getParameterValues("itemStatus1");
      String[] statCB2=request.getParameterValues("itemStatus1");

So i do believe your item status is equal to 1. Especially because on your Js you have the following code. 
   ... "&itemStatus1=" +dropdown1[i]+ ...

So itemStatus1 will be equal to the item on dropdown1[i]. Therefore itemStatus1 is not equal to count or to the size of dropdown1. It is only equal to the number of items in dropdown1 at index (i) which i believe is 1; and you can always use alert() or console.log() to test that.
UPDATE: 
You said that count = 18, but you do not initialize statarr2 using count. You initialize it using statCB2.length.
     int[] statarr2=new int[statCB2.length];

In turn statCB2.length is also not initialized using count it is initialized using request.getParameterValues("itemStatus1");
      String[] statCB2=request.getParameterValues("itemStatus1");

So i do believe your item status is equal to 1. Especially because on your Js you have the following code. 
   ... "&itemStatus1=" +dropdown1[i]+ ...

So itemStatus1 will be equal to the item on dropdown1[i]. Therefore itemStatus1 is not equal to count or to the size of dropdown1. It is only equal to the number of items in dropdown1 at index (i) which i believe is 1; and you can always use alert() or console.log() to test that.

If you want itemStatus1 to be = to the size of the dropdown1 then insted of
     ... "&itemStatus1=" +dropdown1[1]+ ...  

you should use
     ... "&itemStatus1=" +dropdown1.length+ ...  or 

     ... "&itemStatus1=" +dropdown1.size+ ...   (whichever is correct).


Also the other alternative is not play around with itemStatus1 and instead initialize your statCB2 array using count or dropdown1.length 
String[] statCB2= new String[count] or  String[] statCB2= new String[dropdown1.length] 

That should do the trick

I agree that size of itemarr should be bigger .but the problem is size of statarr2 is 1.it should be 18.

I am not still clear .can you tell me where to make the change?

but the concept here is i am passing the values of dropdownlist1 using for loop(@jsfile).based on the number of values, here(jsp file) the size of string array should be created.pls check how i am retrieving kot and item code.

The problem is i cannot debug your code. To help you i need to know which line in the jsp file is giving you the error, also the size/length and value of itemStatus1

See the problem is that you are assuming that kotarr2, kotCB2, itemarr2, itemCB2, statarr2, statCB2, itemStatus1 and dropdown1 all have the same size. if any of them is smaller it will give you trouble.
I don't think you should be using itemarr2.length as your control value in all of the loops. try to use arrays with the same size. So for kotarr2 try looping using kotCB2.lenght. For itemarr2 try looping using itemCB2.length; and for statarr2 try looping using statCB2.lenght.

please check my new changes
