Struts 2:Actions之间的参数 [英] Struts 2: parameters between Actions

查看:107
本文介绍了Struts 2:Actions之间的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:
当我完成一个表单并且操作保存表单的值时,我需要传递一个参数(例如ID),这将转发到结果=成功,我需要将在成功中调用的操作带有ID和其他参数,以便稍后在下一个表单中使用以保存此信息(info-form2和info.form1)...

I have the following question: I need to pass a parameter (for example ID ) when I finish a form and the action save the form's values, this will forward to the result = "success" and I need that the action that will be call in the success come with the ID and other parameters to later use in the next form for save this information (info-form2 and info.form1)...

例如:

FORM1(USER)====成功====> FORM2(ADDRESS)

userForm.html ===================> addressForm.html?user_id = X .. 。(其中X:Id将UserAction抛出(方法:保存)传递给AddressAction(方法:newAddress))

我将非常感谢您的帮助

提前致谢

推荐答案

您使用了forward这个词但是它听起来你想要去一个新页面(address.html)来收集有关该地址的更多信息。如果是这种情况,您需要在用户操作完成后重定向到地址页。

You used the word "forward" but it sounds like you want to go to a new page (address.html) to collect more information about the address. If this is the case, you need to redirect to the address page after the user action completes.

<action name="user" class="UserAction">
  <!-- Redirect to another namespace -->
  <!-- for Struts 2.2 --> <result type="redirectAction">
  <!-- for Struts 2.0 <result type="redirect-action"> -->
    <param name="actionName">collect-address</param>
    <param name="userId">${userId}</param>
  </result>
</action>

$ {userId}语法将在您的UserAction上调用getUserId并传递您在问题:addressForm.html?user_id = X. collect-address可以有一个成功的结果,转到addressForm.html。 此处的文档。如果您想避免使用其他操作,您可以尝试使用结果类型=重定向和通过这种方式传递信息。

The ${userId} syntax will call getUserId on your UserAction and pass that parameter as you showed in your question: addressForm.html?user_id=X. collect-address can have a success result that goes to addressForm.html. Docs here. If you want to avoid using another action, you can try using the result type="redirect" and pass things through that way.

如果你真的想转发,你可以使用动作链接。这是 Ted Husted对Struts2团队的劝阻但是它可能适合你。

If you really want to forward, you can use action chaining. This is discouraged by Ted Husted on the Struts2 team but it may work for you.

尝试将所有代码完成此请求到一个操作中,并使用帮助器或服务类进行用户和地址,而不是动作链接。分离和重用代码而不是动作链。

Instead of action chaining, try to bring all the code to complete this request into a single action and use helper or service classes for User and Address to separate and reuse the code instead of "action chaining".

这篇关于Struts 2:Actions之间的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆