单选按钮组名称

时间:2015-06-15 04:35:14

标签: java jsp

我在数据库中填充的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>

当我检索值时,我得到零点异常

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

单选按钮名称在html中显示为rdCat_1,rdCat_2等。

检索它的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

最简单的方法是保存隐藏输入中的项目数,例如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
}
相关问题