[英]Radio button group name
I have a radio button group in a jsp page populated from database as follows; 我在从数据库填充的jsp页面中有一个单选按钮组,如下所示;
<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. 单选按钮名称在html中显示为rdCat_1,rdCat_2等。
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: 最简单的方法是将项目数保存在隐藏的输入(例如itemsNumber)中,并使用for循环获取参数的实际值:
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.