When porting an application from Struts 1 to Struts 2
In some places, the same class of actions was used for different types of views based on query parameters.
For example: if createType is 1, you need to add one parameter, or if createType is 2, you need to add some more additional parameters, for example, I need to pass dynamic parameters to other actions using ActionForward .
<strong> struts-config.xml
<action path="/CommonAction" type="com.example.CommonAction" scope="request"> <forward name="viewAction" path = "/ViewAction.do"/> </action>
Action class
public class CreateAction extends Action { public ActionForward execute(ActionMapping m, ActionForm f, HttpServletRequest req, HttpServletResponse res) throws ServletException, Exception { String actionPath = m.findForward("viewAction").getPath(); String createType = req.getParameter("createType"); String params = "&action=view"; if("1".equals(createType)){ params = params + "&from=list"; }else if("2".equals(createType)){ params = params + "&from=detail&someParam=someValue"; }
But I canβt do the same in Struts 2. Is it possible to use ActionForward with dynamic parameters in Struts 2?
source share