Recently encountered a form form submission needs to send the ID of the selected checkbox and name to the background, but the El expression can not be directly spliced with the + number of characters, it is very uncomfortable, so I want to use this method.
JSP page Part code:
<Prename= "Code"class= "html"><inputtype= "hidden"ID= "Productarray"name= "Productarray"value=""/><C:setvar= "Up"Scope= "Request"value="|"></C:set> <C:foreachvar= "Pa"Items= "${productsarray}"><inputtype= "checkbox"name= "Productarray"value= "${pa.id}${up}${pa.name}"></C:foreach>
JS Code:
var obj = document.getelementsbyname ("Productarray"); var check_val = []; for inch obj) { if(obj[k].checked) { check_val.push (obj[k].value); } }
Java code:
String Productarr = Httpreq.getparameter ("Productarray");if(Productarr! =NULL&& Productarr! = "") {String productarray[]= Productarr.split (","); Logger.info ("Productarray length--------------" +productarray.length); for(inti = 0; i < productarray.length; i++) {String Tempvalue=Productarray[i]; StringTokenizer STKR=NewStringTokenizer (Tempvalue, "|"); if(Stkr.hasmoreelements ()) {Productentryid=Stkr.nexttoken (); ProductName=Stkr.nexttoken (); } } }
Finished, the value is successful.
PS: Is it possible to use Httpreq.getparametervalues ()
Questions about check box multiple values to the background