简体   繁体   中英

Radio button group name

I have a radio button group in a jsp page populated from database as follows;

<c:forEach var="attCat" items="${attCat}">
                            <input type="radio" name="rdCat_${iter.index}" value="${attCat.catId}"><span style="font-size: x-small;">${attCat.category}</span>
                        </c:forEach>

when I retrieve the values I get null point exception

String[] cat = request.getParameterValues("rdCat_${iter.index}");

the radio button names appear in the html as rdCat_1, rdCat_2 etc.

what is the correct way of retrieving it?

The simplest way is to save the number of items in a hidden input say itemsNumber and use a for loop to get the actual values of the parameters:

int itemsNumber=Integer.parseInt(request.getParameter("itemsNumber"));
for(int i=1;i<=itemsNumber;i++){
  String cat=request.getParameter("rdCat_"+i);
  //then you can do processing with the above value
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM