Hello, I am trying to create a jsp form with 4 options the user can only select 2 of the four options and are blocked from selecting more and given a prompt if they try to. I am not sure how to create a check to see how many checkboxes they have used, I think I should be using an array and a loop but I am struggling to find a solution

<form ACTION="page2.jsp">

Opt 1 <input type="checkbox" name="id" value="check1 +"> 
Opt  2 <input type="checkbox" name="id" value="check2 +"> 
Opt  3 <input type="checkbox" name="id" value="check3 +"> 
Opt  4 <input type="checkbox" name="id" value="check4 +"> 

<input type="submit" value="Submit">
They are then brought to another page that thanks them for choosing those options which I have stored in array.

  <p><b> Thank you <u><%= session.getAttribute( "username" ) %> </u>for registering </b></p>
                  <%String[] selections = request.getParameterValues("id");
                    if (selections != null && selections.length != 0) {
                 out.println("You have selected: ");
                for (int i = 0; i < selections.length; i++) {