insert several checkbox in oracle using jsp and servlet

0

I need help in how to obtain and transform the values of several checkboxes to insert them in the database with a comma, for example:

Seleccione sus frutas favoritas: <br>
<input type="checkbox" name="frutas" value="manzana">Manzana
<input type="checkbox" name="frutas" value="naranja">Naranja
<input type="checkbox" name="frutas" value="banana">Kanana
<input type="checkbox" name="frutas" value="kiwi">Kiwi
<input type="checkbox" name="frutas" value="pina">Piña

<input type="submit">

when selecting multiple fruits for example "orange", "banana", "kiwi" ... etc

are inserted in the database in the example column "nombre Varuto2 (20) so that it looks like: ('banana, orange, kiwi').

in the servlet I understand that the parameters are collected in a variable that are sent to a method and inserted, but I can not send several checkbox parameters to insert them with that format explained ...

Thanks in advance ...

    
asked by Jordan Blake Told 04.06.2018 в 01:54
source

1 answer

0

In your servlet you have to access the "fruits" parameter of the request, as it is a check box group what arrives is an array, so you could try something like this:

String[] frutas = request.getParameterValues("frutas");

Already with this you could go through fruit and create a String, which would be the one you send to the BD.

String frutasParaBd="";
for(int i=0; i<frutas.lenght;i++){
  frutasParaBd=frutasParaBd+frutas[i]
}

NOTE: please keep in mind @gbianchi's recommendations for the next time you need help

    
answered by 04.06.2018 в 08:49