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

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

问题描述

我有以下问题:当我完成表单并且操作保存表单的值时,我需要传递一个参数(例如 ID ),这将转发到结果 = "success" 并且我需要将在成功中调用的操作与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(用户)====成功"====> FORM2(地址)

userForm.html ====================> addressForm.html?user_id=X ...(其中 X : Id 传递了 UserAction 的抛出(方法:save) 到 AddressAction (method:newAddress))

请我感谢您的帮助

提前致谢

推荐答案

您使用了转发"一词,但听起来您想转到新页面 (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.文档在这里. 如果您想避免使用其他操作,您可以尝试 使用结果类型="redirect" 和通过这种方式传递东西.

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.

如果实在想转发,可以使用action chaining.这是 被 Struts2 团队的 Ted Husted 劝阻,但是它可能对你有用.

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天全站免登陆