Questions about check box multiple values to the background

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.