protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String[] interests = request.getParameterValues("interest"); for (String interest : interests) { // do something with each interest } }
String[] toppings = request.getParameterValues("topping"); if (toppings != null && toppings.length > 0) { for (String topping : toppings) { // add each topping to a list } } else { // display an error message if no toppings are selected }In this example, we retrieve an array of values from a checkbox group with the name "topping" and add each one to a list. We also check to make sure that at least one topping was selected, displaying an error message otherwise. The HttpServletRequest class is part of the javax.servlet.http package, which is part of the Java Servlet API. Therefore, to use this class and its methods, the javax.servlet.http library must be included in the project.