如何在重定向操作中传递ActionMessage和ActionError [英] How to pass ActionMessage and ActionError in redirect action
问题描述
Possible Duplicate:
Can I propagate struts2 ActionErrors between different action classes?
实际应用中.Test1
in action.Test1
公共类Test1扩展了ActionSupport {
public class Test1 extends ActionSupport {
public String execute() {
addActionMessage("Hello in test2");
return SUCCESS;
} else {
addActionError("Please try again");
return INPUT;
}
}
在struts.xml中
in 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>
我想在test2.jsp
推荐答案
我强烈认为应该了解有关框架工作原理的基本概念.对于redirect
,它意味着一个新请求,这将使框架删除与第一个请求相关的所有数据,而请求和响应的新对象将放置在值堆栈中,因此,在您的情况下,您的ActionMessage
和
I'm strongly have the opinion that one should know a basic idea about how a framework works. For redirect
it means a new request and which will make the framework to drop all data related to the first request and new object of request and response will be placed in the values stack and hence in your case your ActionMessage
and ActionError
data lost.
如果您在同一App上下文中进行操作,则更建议使用redirectAction
,如果将redirect
结果的另一个操作用于重定向到另一个URL(网络资源).
More over if you are doing it in same App context its more advisable to use redirectAction
if its going to the other action as redirect
result is used to redirect to another URL (web resource).
要保存数据,您可以使用以下选项
In order to save the data you have these options
- 使用会话保存值并通过其他操作检索值.
- 利用范围
这篇关于如何在重定向操作中传递ActionMessage和ActionError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!