While migrating the application from Struts 1 to Struts 2
In some of the places, the same action class has been used for different type of views, based on the request params.
For example: if the createType
is 1 means need to append one param or if the createType
is 2 means need to append some more extra params, like that I need to pass dynamic params to some other action using ActionForward
.
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";
}//,etc..
String actionUrl = actionPath+"?"+params;
return new ActionForward(actionUrl);
}
}
But, I not able to do the same thing in Struts 2. Is there any possibilities to change ActionForward
with dynamic params in Struts 2 ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…