title: Adding multiple records in JSP and sending selected data to Servlet
body: <p>We have data being displayed in JSP like the image below , all the data is getting displayed from single Array List
  [![enter image description here][1]][1]</p>
  
  <p>Our requirement is to select Champion Strategy &amp; Challenger Strategy for multiple records and send same to Servlet.
  Please suggest a method in which we can select and pass multiple changed \ updated values from JSP to servlet.</p>
  
  <p>All the data is coming from database in a single arraylist and getting displayed in JSP , now my requirement is I should be able to submit jsp only once for multiple records , like I should be able to change Champion Strategy for 2-3 records , challenger Strategy for 2-3 records and with in one submit be able to send data to servlet</p>
  
  <pre><code>&lt;%@page import="java.util.ArrayList"%&gt;
  &lt;%@page import="java.util.List"%&gt;
  &lt;%@page import="java.util.Enumeration"%&gt;
  &lt;%@page import="java.util.Vector"%&gt;
  &lt;%@page import="java.util.TreeSet"%&gt;
  &lt;%@page import="java.util.Iterator"%&gt;
  
  &lt;%@page import="java.sql.Connection"%&gt;
  &lt;%@page import="java.sql.DriverManager"%&gt;
  &lt;%@page import="java.sql.ResultSet"%&gt;
  &lt;%@page import="java.sql.Statement"%&gt;
  &lt;%@page import="com.BTParameterStrategyMaintenanceDetails"%&gt;
  &lt;%@page import="javax.servlet.http.HttpSession" %&gt;
  
  &lt;script&gt;
      function getCListt(val) {
          alert(val);
      }
  &lt;/script&gt;
  
  
  
  &lt;script&gt;
   function OpenClose(obj) {
     HeadObj = eval(obj + "_Head");
     BodyObj = eval(obj + "_Body");
  
     if (BodyObj.style.display=='block') {
       BodyObj.style.display='none';
       SignOffset = HeadObj.innerHTML.indexOf("-");
       HeadObj.innerHTML = "+" + HeadObj.innerHTML.substring(SignOffset+1);
     } else {
       BodyObj.style.display='block';
       SignOffset = HeadObj.innerHTML.indexOf("+");
       HeadObj.innerHTML = "-" + HeadObj.innerHTML.substring(SignOffset+1);
     }
   }
  &lt;/script&gt;
  
   &lt;script type="text/javascript"&gt;
      function GetSelectedTextValue(ddlFruits) {
          var selectedText = ddlFruits.options[ddlFruits.selectedIndex].innerHTML;
          var selectedValue = ddlFruits.value;
  
          alert("Selected Text: " + selectedText + " Value: " + selectedValue);
      }
  &lt;/script&gt;
  
  
  
  
  
  
  
  
  &lt;%
      HttpSession session1 = request.getSession();
      ArrayList sampleStrategyRecords = (ArrayList) session1.getAttribute("allRiskCat");
      System.out.println("number of records to be displayed : " + sampleStrategyRecords.size()); 
  
      %&gt;
      &lt;form action="/getChanges" &gt;
  
      &lt;%for(int i=0;i&lt;sampleStrategyRecords.size();i++){
      String id = "ClickMe"+i+"_Head";
      String id1 = "ClickMe"+i+"_Body";
      String onClick = "ClickMe"+i ;
      %&gt;
  
      &lt;div  id="&lt;%= id %&gt;" onClick="OpenClose('&lt;%= onClick %&gt;')" onMouseOver="this.style.cursor='pointer';" style="color: #000099;"&gt;
      &lt;button&gt;
      Risk Category &lt;%= i %&gt; 
      &lt;/button&gt;
      &lt;/div&gt;
  
  
          &lt;%ArrayList ListIterator = (ArrayList) sampleStrategyRecords.get(i);
          System.out.println("ListIteartor :: "+ListIterator.size());
          System.out.println("**********");%&gt;
          &lt;div id="&lt;%= id1 %&gt;" style="display:none; margin-left:20px"&gt;&lt;table&gt;
  
  &lt;tr&gt;
  &lt;th&gt;Risk Category&lt;/th&gt;
  &lt;th&gt;Channel Description&lt;/th&gt;
  &lt;th&gt;Bureau Level Description&lt;/th&gt;
  &lt;th&gt;Champion Strategy&lt;/th&gt;
  &lt;th&gt;Challenger Strategy&lt;/th&gt;
  &lt;th&gt;S2PC&lt;/th&gt;
  &lt;/tr&gt;
          &lt;%
          for(int j=0;j&lt;ListIterator.size();j++){
  
              BTParameterStrategyMaintenanceDetails bean = (BTParameterStrategyMaintenanceDetails)ListIterator.get(j);
  
              ArrayList updatedList = new ArrayList();%&gt;
  
              &lt;tr&gt;
              &lt;td align = "left"&gt;&lt;%= bean.getRiskCategory() %&gt;&lt;/td&gt;
              &lt;td align = "left"&gt;&lt;%= bean.getChannelDescription() %&gt;&lt;/td&gt;
              &lt;td align = "left"&gt;&lt;%= bean.getBureauLevelDescription() %&gt;&lt;/td&gt;
              &lt;td align = "left"&gt;&lt;select name="champDesc" id="champDesc" onchange=updatedList.add(bean) &gt;
  
              &lt;%System.out.println("updated list size :: "+ updatedList.size()); %&gt;
  
                  &lt;%if (bean.getChampStrategyDesc() != null) {
                      for(int s=1;s&lt;10;s++){
  
                      if(bean.getChampStrategyValue().equals(Integer.toString(s))){
  
                      %&gt; 
  
                      &lt;option value="&lt;%=bean.getChampStrategyValue()%&gt;"  selected="selected" &gt; Champion Strategy &lt;%=bean.getChampStrategyValue()%&gt; &lt;/option&gt;
                  &lt;%}else{
  
                      %&gt;
                      &lt;option value="&lt;%= s %&gt;"&gt;Champion Strategy &lt;%=s %&gt;&lt;/option&gt;
                  &lt;%} 
                  }
                  }%&gt;
  
  
  
              &lt;/select&gt;&lt;/td&gt;
              &lt;td align = "left"&gt;&lt;select name="clngrDesc" id="clngrDesc"&gt;
              &lt;%if (bean.getChallengerDesc()!= null) {
                      for(int s=1;s&lt;10;s++){
  
                      if(bean.getChallengerValue().equals(Integer.toString(s))){%&gt; 
                      &lt;option value="&lt;%=bean.getChallengerValue() %&gt;" selected="selected"&gt; Challenger Strategy &lt;%=bean.getChallengerValue() %&gt; &lt;/option&gt;
                  &lt;%}else{
  
                      %&gt;
                      &lt;option value="&lt;%= s %&gt;"&gt;Challenger Strategy &lt;%=s %&gt;&lt;/option&gt;
                  &lt;%}
                  }
                  }
                   %&gt;
                   &lt;/select&gt;
                   &lt;/td&gt;
              &lt;td align = "left"&gt;
              &lt;select name="s2pc" id="s2pc"&gt;
              &lt;%if (bean.getS2pc()!= null) {
                      for(int s=0;s&lt;101;s++){
  
                      if(bean.getS2pc().equals(Integer.toString(s))){%&gt; 
                      &lt;option value="&lt;%=bean.getS2pc() %&gt;" selected="selected"&gt; &lt;%=bean.getS2pc() %&gt; &lt;/option&gt;
                  &lt;%}else{
  
                      %&gt;
                      &lt;option value="&lt;%= s %&gt;"&gt;&lt;%=s %&gt;&lt;/option&gt;
                  &lt;%}
                  }
                  }
                   %&gt;
                   &lt;/select&gt;
              &lt;/td&gt;
  
              &lt;/tr&gt;
  
  
          &lt;%} %&gt;
          &lt;/table&gt;&lt;/div&gt;
   &lt;% }
      session1.setAttribute("checkList",sampleStrategyRecords);
      ArrayList checkList = (ArrayList) session.getAttribute("checkList");
      System.out.println("checkList size :: "+checkList.size());
  %&gt;
  
  &lt;input class="DataEntryButton" name="submit_button" type="submit" value="Submit" /&gt;
  
  
  
  &lt;/form&gt;
  </code></pre>