【问题标题】:Struts2 Infinite recursion detected检测到 Struts2 无限递归
【发布时间】:2016-11-24 16:18:46
【问题描述】:

我有一个重定向到自身的 struts2 链结果,但它不会创建无限循环,因为有一个条件最终将评估为 false,然后递归将停止。我必须使用链而不是redirectAction,因为我需要一个重定向Action 无法执行的POST 请求。

这是我遇到的异常

Could not execute action
Infinite recursion detected: [/view/myAction!myMethod, /view/myAction, /view/myAction] - [unknown location]
    at com.opensymphony.xwork2.ActionChainResult.execute(ActionChainResult.java:214)

我已经通过了基于无限循环检测的 xwork jar。它查看链历史,如果找到动作名称,它会抛出异常。最大递归被硬编码为 1。

有没有办法处理异常或增加允许的最大递归数或在链接时手动重置链历史?

【问题讨论】:

  • 一个动作 chaineditself,它使用业务变量来检测何时链接或中断?这听起来像是灾难的惊人秘诀。重新考虑整个操作。不要链接/重定向到自身,根本不要链接,不要使用 POST,使用 POST / REDIRECT / GET。如果您需要操作中的通用逻辑,请提取该逻辑并将其放入操作之外的业务组件中,然后从您想要的所有操作中调用它。

标签: java recursion model-view-controller struts2 action


【解决方案1】:

我找到了一种从拦截器中操纵链历史的方法

    final ActionContext context = invocation.getInvocationContext();
    LinkedList<String> chainHistory = (LinkedList<String>) context.get("CHAIN_HISTORY");
    // context.put("CHAIN_HISTORY", null);

【讨论】:

    猜你喜欢
    • 2012-03-26
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 2018-06-22
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    相关资源
    最近更新 更多