Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

jsp checkbox display for loop value according to array will have duplicatio

843840Feb 9 2009 — edited Feb 9 2009
The following code displaying multiple checkbox with same value is the checkbox depends on the for loop. When the arr.length increases, the checkbox number for the same value will increase.

However, I do not know how to fix it.

I want to databind the data with checkbox, when member comes back, he can view the checked items. For each time of update, an array length increases, the checkbox number for the same item also increases.
<%  
String sql = "SELECT s.id as id, s.cook as cook, m.cooking as e FROM cooking s join member m where m.id=" + myID;
ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
String arr[]= new String [rs.getString("e").split("\\,").length];
int i;
for(i=0;i<arr.length;i++)
{
arr = rs.getString("e").split("\\,");
%>
<input TYPE=checkbox NAME="cooking" VALUE="<%=rs.getInt("id")%>" <%if(rs.getInt("id")==Integer.parseInt(arr)){out.print("checked");}%>><%=rs.getString("cook")%><BR>
<%
}
}%>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 9 2009
Added on Feb 9 2009
1 comment
526 views