【问题标题】:How do you obtain the value of struts.action.extension in a struts2 interceptor?如何在 struts2 拦截器中获取 struts.action.extension 的值?
【发布时间】:2009-05-28 13:14:00
【问题描述】:

我需要从拦截器访问 struts.xml 文件中的 struts.action.extension 值。有什么建议吗?

【问题讨论】:

    标签: java struts2 interceptor


    【解决方案1】:

    我意识到答案可能是针对以前版本的 struts,它在我使用的 struts 版本(struts v2.2)中不起作用。不过,以下确实有效...

    final ActionContext context = actionInvocation.getInvocationContext();    
    com.opensymphony.xwork2.util.ValueStack vs=context.getValueStack();
    ((ActionMapping)vs.getContext().get("struts.actionMapping")).getExtension();
    

    ... 其中 ActionMapping 是 org.apache.struts2.dispatcher.mapper.ActionMapping。

    认为它可能会对某人有所帮助。

    【讨论】:

    • 除了使用字符串“struts.actionMapping”,您还可以使用常量“ServletActionContext.ACTION_MAPPING”,以防他们决定在未来版本中更改其值。
    【解决方案2】:

    感谢 Struts 用户列表中的 Musachy Barroso,我在拦截器中添加了以下内容:

    /**
     * @param strutsActionExtension the strutsActionExtension to set
     */
    @Inject(StrutsConstants.STRUTS_ACTION_EXTENSION) //Note this isn't necessarily supported
    public void setStrutsActionExtension(String strutsActionExtension) {
        this.strutsActionExtension = strutsActionExtension;
    }
    

    正如 Wes Wannemacher 在同一个列表中所指出的,这实际上并不支持,但在未来的版本中极不可能发生变化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      相关资源
      最近更新 更多