如何从动态创建的HTML表中获取特定行的单元格数据? [英] How to get cell data of specific row from the dynamically created HTML table?

查看:100
本文介绍了如何从动态创建的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");
// ...

这篇关于如何从动态创建的HTML表中获取特定行的单元格数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆