【问题标题】:Struts2 param within result not working结果中的Struts2参数不起作用
【发布时间】:2015-04-27 17:48:04
【问题描述】:

似乎我应该能够在 strut.xml 中定义 PER 结果的参数,而不是全局的,但我无法让它工作。以下是有效的方法:

<action name="actThing" class="Thing" method="execute">
    <interceptor-ref name="newStack" />
    <param name="parentObject">Parent</param>
    <result name="Edit">jspEditThing.jsp</result>
    <result name="Add">jspAddThing.jsp</result>
</action>

在这种情况下,当调用 Thing.execute 时,会设置 parentObject 变量。但是在这里:

<action name="actThing" class="Thing" method="execute">
    <interceptor-ref name="newStack" />
    <result name="Add">
        <param name="location">jspAddThing.jsp</param>
        <param name="parentObject">Parent</param>
    </result>
    <result name="Edit">jspEditThing.jsp</result>
</action>

它没有。因为它在第一种情况下有效,所以我当然有正确的设置/吸气剂,而且我没有收到任何错误。我错过了什么?

谢谢。

【问题讨论】:

    标签: java jsp struts2 action param


    【解决方案1】:

    它不起作用,也不应该因为参数应用于结果,而不是操作。动作后执行结果,所有参数都应该已经设置好了。

    param 标签在Result 对象上设置一个属性。最常设置的属性是location,它通常指定Web 资源的路径。 param 属性是另一个智能默认值。

    【讨论】:

      【解决方案2】:
      <action name="actThing" class="Thing" method="execute">
                  <result name="Add">
                      <param name="includeProperties">Parent.*</param>
                  </result>
              </action>
      

      现在您的父对象及其所有属性和子对象都将可用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-23
        • 2018-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-26
        相关资源
        最近更新 更多