source file name: MultiSelection.html

<html>

    <head>

        <title>Multi Selected Control </title>

    </head>

    <body>

        <form action="http://localhost:8080/ServletPrgs/MiltiselectionServlet" method="post" >

            Name:  <input type="text" size="40" name="name" >

             <br>

             Address: <input type="text" size="60"    name="add"  >

             <br>

             Mobile No: <input type="number" name="mbo" >

             <br>

             Gender:

             <input type="radio" name="gen" value="Male" > Male

             <input type="radio" name="gen" value="Female" > Female

             <br>

            <label for="cars">Choose a car:</label>

            <br>

            <input type="checkbox" name="cars" value="Flat"> Fiat

            <input type="checkbox" name="cars" value="Alto" checked> Alto

            <input type="checkbox" name="cars" value="I-10"> I-10

            <input type="checkbox" name="cars" value="Swift" > Swift                 

            <br>

             <label for="browsers" >Choose a Browsers:</label>

             <br>


       <select id="browsers" name="browsers" size="4" multiple >

      <option value="Internet Explorer">IE</option>

      <option value="Firefox">Firefox</option>

      <option value="Chrome">Chrome</option>

      <option value="Opera">Opera</option>

      <option value="Safari">Safari </option>

       </select>

             <input type="submit" value="Submit" > 

        </form>

    </body>

</html>

output:


source file name: MultiSelectionServlet.java

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = {"/MiltiselectionServlet"})
public class MiltiselectionServlet extends HttpServlet 
{

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            
            out.println("Name: "+request.getParameter("name"));
            out.println("<br>Address "+request.getParameter("add"));
            out.println("<br>Mobile no: "+request.getParameter("mbo"));
            out.println("<br>Selected Gender "+request.getParameter("gen"));
            String[] cars=request.getParameterValues("cars");
            out.println("<br> Selected cars: ");
            for(int i=0;i<cars.length;i++)
                out.println(cars[i]+" ");
            String[] bow=request.getParameterValues("browsers");
            out.println("<br> Selected Browsers: ");
            for(int i=0;i<bow.length;i++)
                out.println(bow[i]+" ");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

output: