Java Struts 1: forward from action to action. Passing data through ActionForms

前端 未结 3 1182
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 09:55

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 requ

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-13 10:08

    Sounds like this could get messy, I'd keep this simple and use the ActionForm only to store Request data.

    public class FormA extends ActionForm {
        public int intA;
        public int commonInt;
    }
    

    Once the Request has been submitted take the data out of the ActionForm and stuff it into the session somewhere, either directly, or into a data holder within the session to maintain this kind of information.

    public class ActionTo extends DispatchableAction {
      public ActionForward recv(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) {
        FormA form = (FormA)form;
    
        DataHolder dataHolder = request.getSession().getAttribute("dataHolder");
        dataHolder.setCommonInt(commonInt);
        dataHolder.setIntA(intA);
    
        return mapping.findForward("send");
      }
    }
    

    Ideally, if you're not heavily invested in Struts 1 I'd take a look at Struts 2.

提交回复
热议问题