JSP and HTML - Naming check boxes with different names from a loop
I have something like this in my code
开发者_开发知识库<% while (i.hasNext()) {
Object obj = i.next();
...
%>
...
<input type="checkbox" name="ticketCheck"/>
...
<% } %>
How can I make the names become ticketCheck1, ticketCheck2 etc so I can reference a corresponding object that displays?
assuming tickets is the collection or array of ticket
<c:forEach var="ticket" items="${tickets}">
<TR>
<input type="checkbox" name="${ticket}"/>
</TR>
</c:forEach>
Here is a different example. This assumes that tickets is a list of objects and that for each object there is defined a getValue() and getName() method.
<c:forEach var="item" items="${tickets}">
...
...
<input type="checkbox" value="${item.value}" name="${item.name}"/>
...
...
精彩评论