2015-06-15 69 views
0

我有一个单选按钮组在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等

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

回答

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 
}