如何从动态创建的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


  1. 连接到MySQL数据库


  2. 根据第2步
  3. 中返回的行,以热烈的方式构建HTML表格
  4. 表格的第一列包含复选框
  5. JSP页面包含提交按钮

  6. 为某些行选择复选框

  7. 点击提交按钮,哪一行复选框被选中?

  1. Connect to MySQL Databse
  2. Fetch rows from table based on criteria
  3. Construct HTML table dybamically based on the rows returned in step 2
  4. The first column of table contains checkbox
  5. JSP page contains a Submit button
  6. Select checkbox for some row(s)
  7. 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");
// ...