Java Struts 1:从动作转向动作。通过ActionForms传递数据

编程入门 行业动态 更新时间:2024-10-24 17:21:31
本文介绍了Java Struts 1:从动作转向动作。通过ActionForms传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们一直在尝试从一个操作重定向到另一个操作,希望数据将在相应的 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传递数据

本文发布于:2023-10-07 17:31:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470036.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动作   数据   Java   Struts   ActionForms

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!