title: Pass some checkbox values from one JSP to another
body: <p>I've been having problems passing parameters from one .jsp to another.</p>
  
  <p>I have two .jsp (1 and 2). In 1 I get some data from a database and show the user a bunch of checkboxes (depending on the data I got before). The user has to check one or more of the checkboxes, the selected will be deleted in my database in 2. (It´s something like "Select the numbers you want to delete").</p>
  
  <p>I don't know how to pass the selected checkboxes and the value from 1 to 2.
  I tried with javascript/jQuery, trying to know if a checkbox is checked and its value, add the value to a hidden field and use the request in 2 to get it.</p>
  
  <p><strong>1.jsp</strong></p>
  
  <pre><code>&lt;%
      HttpSession sesion = request.getSession();
  
      Company company = (Company) sesion.getAttribute("company");
      List&lt;Phone&gt; phones = company.getTelefonos();
  %&gt;
  &lt;form id="formulario" method="POST" action="desMul_Final.jsp"&gt;
  &lt;fieldset&gt;
      &lt;legend&gt;Numbers&lt;/legend&gt;
      &lt;%
          Iterator&lt;Phone&gt; it1 = phones.iterator();
          while(it1.hasNext()){
              Phone t = it1.next();
              String number = t.getNumero();
      %&gt;
      &lt;p&gt;
          &lt;input name=check id="t_&lt;%=number%&gt;" type=checkbox value="&lt;%=number%&gt;" /&gt; &lt;%=number%&gt;.
      &lt;/p&gt;
      &lt;%
          }
      %&gt;
  &lt;/fieldset&gt;
  &lt;p class="buttons"&gt;
      &lt;button type=submit onclick="javascript: pick();"&gt;Continue&lt;/button&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Javascript/jQuery</strong></p>
  
  <pre><code>function pick(){
  var counter = 0;
  $("#formulario fieldset p").each(function(index){
      var field;
      $(this).children("input").each(function() {
          if($this.is(':checked')){
              field = $(this).val();
          }
      });
      index = index + 1;
  
      texto = "&lt;input type=hidden name=phone_"+index+" value="+field+" /&gt;";
      $("#formulario").append(texto);
  
      counter = index;
  });
  cant = "&lt;input type=hidden name=amount id=amount value="+counter+" /&gt;";
  $("#formulario").append(cant);
  }
  </code></pre>
  
  <p><strong>2.jsp</strong> (here I only try to know if I have the info)</p>
  
  <pre><code>&lt;%
      int amount = Integer.valueOf(request.getParameter("amount"));
      System.out.println(amount);
  
      for(int i = 1; i &lt;= amount; i++){
              String s = request.getParameter("phone_"+i);
          System.out.println(s);
      }
  %&gt;
  </code></pre>
  
  <p>When I try to access to <code>request.getParameter("amount")</code> I get an <code>java.lang.NumberFormatException: null</code> so I think my Javascript/jQuery is wrong.</p>
  
  <p>How can I solve this?.</p>