checking which check boxes are selected using JAVA ( a jsp)

后端 未结 4 1446
灰色年华
灰色年华 2021-01-02 13:09

I am trying to create a servlet that displays a simple form with checkboxes , when the user selects the number of checkboxes he wants and clicks on a \"confirm\" the POST re

4条回答
  •  我在风中等你
    2021-01-02 13:43

    This is actually the HTML form behavior question. When you check a few checkboxes with one "name" attribute and different "value" attributes and press submit button, your browser will send request to the server with checked checkbox values. So you can get value names from this url parameters.

    For example:

    I have a bike
    I have a car

    If you check both of checkboxes your server will receive this parameters like so:

    http://example.com/your_page.jsp?vehicle=Bike&vehicle=Car 
    

    After that you can get values like this:

    String checkboxValues = request.getParameter("vehicle");
    

    checkboxValues gets all values separated by comma.

提交回复
热议问题