如何从 JSP 获取正在运行的 bean 列表?
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的解决方案是发送地图而不是列表。
迭代将使用 基于地图的方式为每个 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.
您必须向服务器发送 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.