项目中遇到了需要从一个action的一个方法重定向到另一个action的一个方法,并且需要带参数,网上找了很多资料没有我想要的,后来发现了这位大佬的博客 https://blog.youkuaiyun.com/heisetoufa/article/details/84437278带给我一些启发。因为我的项目比较大,暂时先借用一下这位大佬的代码。
package com.test.action;
public class TestAction extends BaseAction implements Preparable {
Test test = new Test();
public String test() throws Exception {
test.setId(111111111);
return "issueOrder";
}
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
}
<action name="toPay" class="OrderPayAction" method="toPay">
<result name="issueOrder" type="redirect" >/airAction/issueOrderAction.do?test.id=${test.id}</result>
</action>
<package name="airAction">
<action name="issueOrderAction" class="airActionClass" method="issueOrderAction">
<result name="success" type="redirect" >success.jsp</result>
</action>
</package>
在大佬的博客中定义了test对象,在我的代码中我定义了全局变量,这里呢大家可以根据自己的需要自己定义,但是有一点需要注意的是,不管是对象还是全局变量,都需要有它自己的get和set方法,要不然另一个action的方法拿不到参数值。如果定义的是全局变量,/airAction/issueOrderAction.do?test.id=${test.id} 这行中的问号后面的参数就需要变化了,前面的是你另一个方法中getparameter(" 参数") 的值,大括号中的是你赋值的全局变量。