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

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

    1. <small id='UGnyo'></small><noframes id='UGnyo'>

        <tfoot id='UGnyo'></tfoot>
        <legend id='UGnyo'><style id='UGnyo'><dir id='UGnyo'><q id='UGnyo'></q></dir></style></legend>

        在 Struts 2 中重定向到具有未知数量参数的另一个动作

        Redirecting to another action with unknown amount of parameters in Struts 2(在 Struts 2 中重定向到具有未知数量参数的另一个动作)

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

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

                  <tbody id='Pveuk'></tbody>
                <legend id='Pveuk'><style id='Pveuk'><dir id='Pveuk'><q id='Pveuk'></q></dir></style></legend>

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

                • 本文介绍了在 Struts 2 中重定向到具有未知数量参数的另一个动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个登录操作,在成功执行后重定向到上一页(我将上一页存储在我的会话中,以便以后获取它).在 Struts2 中,我可以找到两种方法来进行这种重定向:

                  I have a login action which after successful execution redirects to the previous page (I store the previous page in my session so I can fetch it later). In Struts2, I can find two ways to do this redirection:

                      <action name="login" class="com.myapp.login.Login">
                          <result name="redirect" type="redirect">${previousAction.requestURL}</result>   
                      </action>
                  

                  在这个例子中,将调用 getPreviousAction().getRequestURL() 方法(这是一个自制的方法,它不是 Struts2 的原生方法),这将返回上一页的 URL意图,例如:

                  In this example, the getPreviousAction().getRequestURL() method (this is a selfmade method, its not native to Struts2) will be invoked and this will return the URL of the previous page as intended, for example:

                  somenamespace/index.action
                  

                  还有另一种类型的重定向:

                  There is also another type of redirection:

                  <action name="login" class="com.myapp.login.Login">
                       <result type="redirectAction">
                          <param name="actionName">${previousAction.name}</param>
                          <param name="namespace">/${previousAction.namespace}</param>
                      </result>   
                  </action>
                  

                  我想使用这种`redirectAction 结果类型,因为它更简洁.但是,当查询参数是 URL 的一部分时,我遇到了问题.例如:

                  I want to use this `redirectAction result type because it is much cleaner. But, I have a problem when query parameters are part of the URL. For example:

                  somenamespace/index.action?name=john&age=50
                  

                  我知道我可以在我的 struts.xml 中添加这些硬编码的参数,但问题是我的登录操作应该重定向到 any 以前调用的操作,而我没有事先知道之前的操作有哪些查询参数.这与您确切知道要重定向到哪个操作的典型用例不同

                  I know I can add these params hardcoded in my struts.xml, but the problem is my login action should redirect to any previously invoked action, and I do not know beforehand which query parameters the previous actions had. This is different from the typical usecase where you know exactly to which action you're redirecting to

                  我发现一个非常糟糕的解决方案是添加 every 可能的参数(我在 struts.xml 中的所有操作的所有参数的集合),然后使用以下选项:

                  A very bad solution I found was adding every param possible (the collection of all params of all my actions in struts.xml) and then use the option:

                  <param name="suppressEmptyParameters">true</param>
                  

                  推荐答案

                  您可以从 ActionMapping 中保存动作名称、命名空间和参数.

                  You can save action name, namespace, and parameters from the ActionMapping.

                  ActionMapping mapping = ServletActionContext.getActionMapping();
                  

                  您也可以保存查询字符串而不是参数映射.

                  You can also save query string instead of parameter map.

                  String params = request.getQueryString();
                  

                  要将参数动态添加到 redirectAction 结果,您应该在动态参数中使用 OGNL.

                  To add parameters dynamically to redirectAction result you should use OGNL in a dynamic parameter.

                  <param name="actionName">${previousAction.name +'?'+ parameters}</param>
                  

                  假设您有一个用于 parameters 的 getter,并从保存先前查询字符串、操作名称和命名空间的会话中对其进行初始化.

                  Supposed you have a getter for parameters and initialized it from session where you saved previous query string, action name, and namespace.

                  这篇关于在 Struts 2 中重定向到具有未知数量参数的另一个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的游戏框架.有什么建议吗?)
                    <bdo id='iKibf'></bdo><ul id='iKibf'></ul>

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

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