如何从动态创建的HTML表中获取特定行的单元格数据?
问题描述:
如何从JSP中的动态创建的HTML表中获取特定行的单元格数据?
How to get cell data of a specific row from the dynamically created HTML table in JSP?
我以下面的方式创建JSP页面
I am creating JSP Page in the following way
- 连接到MySQL数据库
-
- 根据第2步 中返回的行,以热烈的方式构建HTML表格
- 表格的第一列包含复选框
- JSP页面包含提交按钮
- 为某些行选择复选框
- 点击提交按钮,哪一行复选框被选中?
- 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 Submit button
- Select checkbox for some row(s)
- On Submit button click, How can i check which row checkbox is selected?
答
为所有复选框指定相同的名称,行ID。
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>
然后您可以使用 的HttpServletRequest#getParameterValues()
,如下所示:
Then you can obtain the checked ones in the server side using HttpServletRequest#getParameterValues()
as follows:
String[] rowids = request.getParameterValues("rowid");
// ...