<tfoot id='PwugC'></tfoot>
    • <bdo id='PwugC'></bdo><ul id='PwugC'></ul>
    <i id='PwugC'><tr id='PwugC'><dt id='PwugC'><q id='PwugC'><span id='PwugC'><b id='PwugC'><form id='PwugC'><ins id='PwugC'></ins><ul id='PwugC'></ul><sub id='PwugC'></sub></form><legend id='PwugC'></legend><bdo id='PwugC'><pre id='PwugC'><center id='PwugC'></center></pre></bdo></b><th id='PwugC'></th></span></q></dt></tr></i><div id='PwugC'><tfoot id='PwugC'></tfoot><dl id='PwugC'><fieldset id='PwugC'></fieldset></dl></div>

    <small id='PwugC'></small><noframes id='PwugC'>

        <legend id='PwugC'><style id='PwugC'><dir id='PwugC'><q id='PwugC'></q></dir></style></legend>
      1. 如何在 Struts 2 中使用动态参数更改 ActionForward

        How to change ActionForward with dynamic params in Struts 2(如何在 Struts 2 中使用动态参数更改 ActionForward)
          1. <tfoot id='BqdPy'></tfoot>

            <i id='BqdPy'><tr id='BqdPy'><dt id='BqdPy'><q id='BqdPy'><span id='BqdPy'><b id='BqdPy'><form id='BqdPy'><ins id='BqdPy'></ins><ul id='BqdPy'></ul><sub id='BqdPy'></sub></form><legend id='BqdPy'></legend><bdo id='BqdPy'><pre id='BqdPy'><center id='BqdPy'></center></pre></bdo></b><th id='BqdPy'></th></span></q></dt></tr></i><div id='BqdPy'><tfoot id='BqdPy'></tfoot><dl id='BqdPy'><fieldset id='BqdPy'></fieldset></dl></div>
            <legend id='BqdPy'><style id='BqdPy'><dir id='BqdPy'><q id='BqdPy'></q></dir></style></legend>

              <bdo id='BqdPy'></bdo><ul id='BqdPy'></ul>

              <small id='BqdPy'></small><noframes id='BqdPy'>

                    <tbody id='BqdPy'></tbody>
                  本文介绍了如何在 Struts 2 中使用动态参数更改 ActionForward的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  将应用程序从 Struts 1 迁移到 Struts 2 时

                  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.

                  例如:如果 createType 为 1 表示需要附加一个参数,或者如果 createType 为 2 表示需要附加一些额外的参数,就像我需要的那样使用 ActionForward 将动态参数传递给其他操作.

                  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>
                  

                  动作类:

                  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 ?

                  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 ?

                  推荐答案

                  您可以使用带有 result 的动态参数,请参阅 动态结果配置.

                  You could use a dynamic parameters with a result, see the dynamic result configuration.

                  在动作中你应该为参数写一个getter

                  In the action you should write a getter for the patrameter

                  private String actionUrl;
                  
                  public String getActionUrl() {
                      return actionUrl;
                  }
                  

                  并配置结果

                  <action name="create" class="CreateAction">
                      <result type="redirect">${actionUrl}</result>
                  </action>
                  

                  所以,常识是像这样重写代码

                  So, the common sense would be rewrite the code like

                  public class CreateAction extends ActionSupport
                  {
                  
                      private String actionUrl;
                  
                      public String getActionUrl() {
                          return actionUrl;
                      }
                  
                      @Override
                      public String execute() throws Exception
                      {
                              String actionPath = "/view";
                              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..
                              actionUrl = actionPath+"?"+params;
                              return SUCCESS;
                      }
                  }
                  

                  如果您需要更好的方法从操作映射创建 url,您可以查看 这个答案.

                  If you need a better way to create the urls from action mapping, you could look at this answer.

                  这篇关于如何在 Struts 2 中使用动态参数更改 ActionForward的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)

                  <legend id='EJcBa'><style id='EJcBa'><dir id='EJcBa'><q id='EJcBa'></q></dir></style></legend>
                    <i id='EJcBa'><tr id='EJcBa'><dt id='EJcBa'><q id='EJcBa'><span id='EJcBa'><b id='EJcBa'><form id='EJcBa'><ins id='EJcBa'></ins><ul id='EJcBa'></ul><sub id='EJcBa'></sub></form><legend id='EJcBa'></legend><bdo id='EJcBa'><pre id='EJcBa'><center id='EJcBa'></center></pre></bdo></b><th id='EJcBa'></th></span></q></dt></tr></i><div id='EJcBa'><tfoot id='EJcBa'></tfoot><dl id='EJcBa'><fieldset id='EJcBa'></fieldset></dl></div>

                      <tbody id='EJcBa'></tbody>

                    <small id='EJcBa'></small><noframes id='EJcBa'>

                    <tfoot id='EJcBa'></tfoot>

                        • <bdo id='EJcBa'></bdo><ul id='EJcBa'></ul>