gpt4 book ai didi

java - 支柱2 : Using data from other actions

转载 作者:太空宇宙 更新时间:2023-11-04 08:05:32 25 4
gpt4 key购买 nike

我有一个 struts 2 项目,其中有 3 个操作执行不同的数据报告功能。我正在创建一个主页操作,以在主页上显示其他 3 个操作的数据片段。

目前我有 Home.action 导入其他 3 个操作,然后使用其他操作对象来获取数据。这感觉不太“正确”,所以我想知道在 Struts 中做到这一点的最佳方法是什么?最好不要过多编辑原来的 3 个 Action 。

最佳答案

我也遇到过类似的困境,我通过在 struts.xml 中定义一个不同的操作来解决它们,该操作仅返回操作的结果(不返回周围的tiles 等)。

然后,我使用 jQuery 使用 Ajax 获取不同的操作,这还有一个额外的好处:实际上让服务器计算不同请求中的不同操作,因此我的用户可以先于其他人看到一些结果,如果您的操作需要 3 秒以上的时间来计算结果,那就太好了。

请注意,这里 Tiles 的使用实际上是完全不相关的。您可以通过使用不同的 JSP 获得相同的效果(假设您想要一点自定义的外观)。

我的 loadBrokerReport 操作在更大的周围图 block (布局)内显示代理报告,但 loadBrokerReportAjax 从相同的 Action 类执行相同的方法,但通过 ajaxReport.jsp 文件呈现结果(这样更简洁,更适合在其他内容旁边显示)。

    <!-- This is the normal action the users select from menu -->
<action name="loadBrokerReport" method="loadBrokerReport" class="ee.reinmets.intra.action.BrokerReportsAction">
<result type="tiles">brokerReport</result>
</action>

<!-- This is the action called via ajax -->
<action name="loadBrokerReportAjax" method="loadBrokerReport" class="ee.reinmets.intra.action.BrokerReportsAction">
<result>/WEB-INF/pages/brokerReports/ajaxReport.jsp</result>
</action>

<!-- This is the tile i'm referencing above, in tiles.xml -->
<definition name="brokerReport" extends="default">
<put-attribute name="body" value="/WEB-INF/pages/brokerReports/normalReport.jsp" />
</definition>

关于java - 支柱2 : Using data from other actions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12145731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com