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

后端 未结 4 1447
灰色年华
灰色年华 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:38

    In your servlet you would use getParameter() like so:

    request.getParameter( "id_of_checkbox" )
    

    That function returns null if the the box is not checked. So you could do something like:

    boolean myCheckBox = request.getParameter( "id_of_checkbox" ) != null;
    

    Now myCheckBox is true if checked, false if not checked.

提交回复
热议问题