【问题标题】:Update particular record on click of specific submit button单击特定提交按钮更新特定记录
【发布时间】:2011-01-27 13:32:45
【问题描述】:

我有一个 Jsp 页面,它显示数据库中的几条记录,每个数据行都有一个提交按钮,点击 servlet 更新数据库。

例如我的 JSP 显示:- CustomerName 客户城市提交按钮。

所以我希望无论哪个客户按下提交按钮,该客户的数据都应该更新。

我可以用提交按钮在 jsp 中显示数据,但不能从 servlet 更新记录。

【问题讨论】:

    标签: jsp servlets


    【解决方案1】:

    将每个提交按钮放在自己的表单中,并带有一个隐藏字段,您可以在其中传递行 ID。

    <td>
        <form action="servleturl" method="post">
            <input type="submit" value="Edit" /> 
            <input type="hidden" name="id" value="${customer.id}" />
        </form>
    </td>
    

    然后你就可以抓住它了

    String id = request.getParameter("id");
    Customer customer = customerDAO.find(Long.valueOf(id));
    // ...
    

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 2013-02-11
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 2015-08-28
      • 2017-05-01
      相关资源
      最近更新 更多