如何在重定向操作中传递 ActionMessage 和 ActionError [重复]

2024-05-17

可能的重复:
我可以在不同的操作类之间传播 struts2 ActionErrors 吗? https://stackoverflow.com/questions/1070111/can-i-propagate-struts2-actionerrors-between-different-action-classes

实际操作中.Test1

公共类 Test1 扩展 ActionSupport {

    public String execute() {
        addActionMessage("Hello in test2");
        return SUCCESS;
    } else {
      addActionError("Please try again");
        return INPUT;
    }
}

在struts.xml中

<action name="test1" class="action.Test1">
        <result name="success" type="redirect">test2</result>
  </action>
<action name="test2" class="action.Test2">
        <result name="success">/test2.jsp</result>
</action>

我要显示ActionMessage and ActionError in test2.jsp


For redirect这意味着一个新的请求,这将使框架删除与第一个请求相关的所有数据,并且请求和响应的新对象将被放置在值堆栈中,因此在您的情况下ActionMessage and ActionError数据丢失。

如果您在同一个应用程序上下文中执行此操作,则更建议使用redirectAction如果它要执行其他操作redirect结果用于重定向到另一个 URL(Web 资源)。

为了保存数据,您有以下选项

  1. 使用会话保存值并在其他操作中检索值。
  2. 利用范围
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在重定向操作中传递 ActionMessage 和 ActionError [重复] 的相关文章

随机推荐