How to get cell data of specific row from the dynamically created HTML table?
How to get cell data of a specific row from the dynamically created HTML table in JSP?
I am creating JSP Page in the following way
- Connect to MySQL Databse
- Fetch rows from table based on criteria
- Construct HTML table dybamically based on the rows returned in step 2
- The first column of table contains checkbox
- JSP page contains a S开发者_C百科ubmit button
- Select checkbox for some row(s)
- On Submit button click, How can i check which row checkbox is selected?
Give all checkboxes the same name, but a different value, e.g. the row ID.
<table>
<c:forEach items="${list}" var="row">
<tr>
<td><input type="checkbox" name="rowid" value="${row.id}"></td>
<td>${row.name}</td>
<td>${row.value}</td>
...
</tr>
</c:forEach>
</table>
Then you can obtain the checked ones in the server side using HttpServletRequest#getParameterValues()
as follows:
String[] rowids = request.getParameterValues("rowid");
// ...
精彩评论