gpt4 book ai didi

apache - Struts 2.3 - 重定向 vs redirectAction

转载 作者:行者123 更新时间:2023-12-04 20:45:13 24 4
gpt4 key购买 nike

redirect之间的主要区别是什么和 redirectAction在 Struts2.3 上下文中。

我在下面看到了 redirect 的 URL和 redirectAction .

我清楚以下几点:

  • 重定向就像 sendRedirect() 方法。创建新请求,清除以前的值堆栈和操作(操作实例、操作错误、字段错误等)不再可用。
  • redirectAction , 控制跳转到不同的 Action (在同一个或其他包中)
  • redirectAction建议重定向。

  • 但是当我实现上面提到的两个例子时,我只需要改变我的 struts.xml .
  • 在这两种情况下,操作都不再可用,
  • 新请求已创建,
  • 生成的 URL 是相同的。

  • 首先,我对 redirectAction Apache 文档中写的声明感到困惑。

    This is better than the ServletRedirectResult because it does not require you to encode the URL patterns processed by the ActionMapper in to your struts.xml configuration files. This means you can change your URL patterns at any point and your application will still work. It is strongly recommended that if you are redirecting to another action, you use this result rather than the standard redirect result.



    其次,我还不是很清楚这两者之间的区别。

    最佳答案

    一种重定向到操作,一种重定向到任意资源。
    actionRedirect对大多数 Struts 2 应用程序更好,因为大多数重定向将发生在应用程序内部的位置,您需要提供的只是其映射中的操作名称。

    你可以用普通的 redirect 做同样的事情,但是您需要提供操作扩展名(如果有),因此它有点丑陋且有点脆弱(例如,如果操作扩展名发生变化,尽管这种情况很少发生)。

    关于apache - Struts 2.3 - 重定向 vs redirectAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19002605/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com