2015-06-15 101 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 
}