title: How to post multiple <input type=“checkbox” /> as array to Java servlet?
body: <p>This question is the same as <a href="https://stackoverflow.com/questions/1978781/how-to-post-multiple-input-type-checkbox-as-array-in-php">How to post multiple &lt;input type=&quot;checkbox&quot; /&gt; as array in PHP?</a>, but I can't make the solution work in my java servlet setup. When using the apporach of adding a [] to the name property of the grouped checkboxes, I only get the first checked option. I am not sure if it is the actual posted array that is containing only one element, or if I'm not accessing it right server side. Here is what I do to check the value in java:</p>
  
  <pre><code>@Override
  public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {  
      for(String name : request.getParameterMap().keySet()){      
          System.out.println(name +": " + request.getParameter(name));        
      }
  }
  </code></pre>
  
  <p>this prints <code>countries[]: US</code>, even if I have more checboxes checked after the US-input. the value changes after which checkbox is the first of the checked ones. What am I doing wrong?</p>
  
  <p>Here is my HTML:</p>
  
  <pre><code>&lt;form action="mypage" method="post"&gt;
      &lt;input id="cb-country-gb" type="checkbox" name="countries[]" class="hide" value="GB"/&gt;
      &lt;input id="cb-country-us" type="checkbox" name="countries[]" class="hide" value="US"/&gt;
      &lt;input id="cb-country-ge" type="checkbox" name="countries[]" class="hide" value="GE"/&gt;
      &lt;input id="cb-country-es" type="checkbox" name="countries[]" class="hide" value="ES"/&gt;
      &lt;button type="submit" class="btn btn-primary"&gt;Search&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>