gpt4 book ai didi

java - Struts 2 - 当第二个操作与表单一起使用时,在操作之间传递参数会丢失

转载 作者:行者123 更新时间:2023-12-01 04:56:08 24 4
gpt4 key购买 nike

我有两个操作类,它们通过 ModelDriven 接口(interface)使用相同的模型。每个 Action 类都与形式相关。我需要在两个操作中将值存储到同一模型。

从第一个操作类(验证后),我通过以下方式将模型驱动模型传递到第二个类:

@Result(name = "success", location = "action2", type = "chain")

在第二个操作类中,我显示了已在第一个操作中存储到模型中的值。

这工作正常,但是当我在第二个操作中执行表单提交时,存储的值从第一次行动开始就丢失了。

因此,第一个操作的数据仅为第一次调用第二个操作而存储。

有什么解决方案可以实现这一点吗?

最佳答案

将您的数据放入 session 中或使用参数,其结果如所述 herethere .

Parameters can be passed to results using the params attribute. The value of this attribute is a string array with an even number of elements in the form {"key0", "value0, "key1", "value1" ... "keyN", "valueN"}. For example:

 @Action(value="/different/url",
results={@Result(name="success", type="httpheader", params={"status", "500", "errorMessage", "Internal Error"})}
)

关于java - Struts 2 - 当第二个操作与表单一起使用时,在操作之间传递参数会丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14111092/

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