我们一直在尝试从一个操作重定向到另一个操作,希望数据将在相应的 ActionForm bean之间传递。第一个操作接收来自浏览器的请求,打印数据字段,并将其转发到另一个操作,该操作打印相同的字段并重定向到JSP。
We've been trying to redirect from one action to another, hoping that data would be passed between corresponding ActionForm beans. The first action receives a request from the browser, prints a data field, and forwards it to another action, which prints the same field and redirects to a JSP.
问题是 ActionTo 打印的值不正确 - 其 commonInt 的默认值为 0 ,而我们预计 35 。
The problem is that ActionTo is printing an incorrect value - its commonInt has a default value of 0, while we expect 35.
这是一个代表示例:
public class ActionFrom extends DispatchableAction{ public ActionForward send(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response){ FormA formA = (FormA)form; formAmonInt = 35; System.out.println("sent: "+formAmonInt); return mapping.findForward("send"); } } public class ActionTo extends DispatchableAction{ public ActionForward recv(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response){ FormB formB = (FormB)form; System.out.println("recv= "+formBmonInt); return mapping.findForward("send"); } }动作表格是:
public class FormA extends ActionForm { public int intA; public int commonInt; } public class FormB extends ActionForm{ public int intB; public int commonInt; }映射:
<action path="/from" type="EXPERIMENT.ActionFrom" name="formA" scope="request" input="something.jsp" parameter="dispatch" unknown="false" validate="false"> <forward name="send" path="/to.do?dispatch=recv" redirect="false"/> </action> <action path="/to" type="EXPERIMENT.ActionTo" name="formB" scope="request" input="something.jsp" parameter="dispatch" unknown="false" validate="false"> <forward name="send" path="/login.do" redirect="false"/> </action>有没有办法实现这个目标?或者两种形式都应该相同?
Is there a way to accomplish this? Or both forms should be the same?
我们尝试的解决方法是通过请求传递内容,但它可能变得庞大而混乱。
The workaround we tried was to pass things through request, but it can get large and messy.
推荐答案实现此目的的方法是对两个操作使用相同的actionform。是否有特定原因需要两种不同的动作形式?如果没有尝试修改第二个动作映射到name =formA,并且动作本身使用FormA而不是FormB。
The way to accomplish this is to use the same actionform for both actions. Is there a specific reason why you need two different actionforms? If not try modifying the second action mapping to name="formA" and the action itself to use FormA rather than FormB.
更多推荐
Java Struts 1:从动作转向动作。通过ActionForms传递数据
发布评论