【问题标题】:ActionMapping in Action class of Struts2Struts2的Action类中的ActionMapping
【发布时间】:2018-06-18 07:15:57
【问题描述】:

我正在 Struts2(2.5.16) 上开发一个应用程序。我遇到了一种情况,我的动作类需要知道它的动作名称(在 struts.xml 中定义)。在struts1中,我们可以使用ma​​pping.getPath()来实现。我们如何在 struts2 中实现这一点?

我的 struts.xml:

    <action name="testAction" class="action.TestAction">
        <result name="success">/success.jsp</result>
        <result name="error">/error.jsp</result>
    </action>

我想在我的 struts2 动作类中获得“testAction”。

谢谢, 苏尼尔

【问题讨论】:

  • 是什么原因?一般来说,由于各种原因,一个动作不需要知道它叫什么。也许有更好的解决方案。

标签: struts2


【解决方案1】:

您是否尝试过使用 ActionContext?

String actionName = ActionContext.getContext().getName();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-20
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多