【发布时间】:2013-07-24 04:31:49
【问题描述】:
将应用程序从 Struts 1 迁移到 Struts 2 时
在某些地方,根据请求参数,相同的操作类已用于不同类型的视图。
例如:如果createType 为1 表示需要附加一个参数,或者createType 为2 表示需要附加一些额外的参数,例如我需要使用@ 将动态参数传递给其他操作987654323@.
struts-config.xml:
<action path="/CommonAction" type="com.example.CommonAction" scope="request">
<forward name="viewAction" path = "/ViewAction.do"/>
</action>
动作类:
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);
}
}
但是,我不能在 Struts 2 中做同样的事情。是否有可能在 Struts 2 中使用动态参数更改 ActionForward ?
【问题讨论】:
标签: java struts2 migration struts actionresult