如何从 JSP 获取正在运行的 bean 列表?

发布于 2024-12-17 20:18:38 字数 244 浏览 5 评论 0原文

我正在使用 Struts 2 和 Eclipse 创建应用程序。

我有一个用于货币汇率的 bean 类(具有属性“货币”、“描述”、“汇率”)。

我使用 DAO 获取数据列表,并使用 在 JSP 中显示它。

但我在每一行添加“新汇率”文本框以“更新”货币汇率。如果文本框有价值,我想同时更新所有内容。如何将 bean 列表从 JSP 获取到操作类?

I am using Struts 2 and Eclipse to create an application.

I have a bean class for Currency Exchange Rate (with properties "currency", "description", "rate").

I get a list of data using a DAO and show it in JSP using <s:iterator>.

But I add "New Rate" text box at every row to "Update" currency rate. I want to update it all at the same time if textbox has value. How do I get lists of beans from my JSP to my action class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七分※倦醒 2024-12-24 20:18:38

最简单的解决方案是发送地图而不是列表。

迭代将使用 基于地图的方式为每个 bean 创建一个文本字段字段名称,可能由货币转换 bean 的 ID 作为键控。

处理操作将使用新值(已由 Struts 2 转换)在操作的 bean 映射中重新保留 bean。

The easiest solution is to send a map instead of a list.

The iteration would create a textfield for each bean using map-based field names, likely keyed by the currency conversion bean's ID.

The processing action would re-persist the beans using the new values, already converted by Struts 2, in the action's map of beans.

唠甜嗑 2024-12-24 20:18:38

您必须向服务器发送 HTTP 请求。您可以使用 Javascript (AJAX) 或基本 HTML 表单来完成此操作。该请求将包含文本框的内容,并将被发送到服务器上的 Java servlet(或 Struts 使用的任何内容)。然后,servlet 将使用请求中发送的数据来更新 Java bean。

You would have to send an HTTP request to the server. You can do this using Javascript (AJAX) or a basic HTML form. The request would contain the contents of the text boxes and would be sent to a Java servlet on the server (or whatever Struts uses). Then, using the data that was sent in the request, the servlet would update the Java bean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文