Java 如何在struts2拦截器中获得struts.action.extension的值?

Java 如何在struts2拦截器中获得struts.action.extension的值?,java,struts2,interceptor,Java,Struts2,Interceptor,我需要从拦截器访问struts.xml文件中的struts.action.extension值。有什么建议吗?多亏了Struts用户列表上的Musachy Barroso,我在我的拦截器中添加了以下内容: /** * @param strutsActionExtension the strutsActionExtension to set */ @Inject(StrutsConstants.STRUTS_ACTION_EXTENSION) //Note this isn't necessa

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

多亏了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在同一个列表中指出的,这实际上不受支持,但在未来的版本中极不可能更改。

我意识到答案可能是针对以前版本的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

我想这可能会对某些人有所帮助。

如果他们决定在将来的版本中更改其值,您也可以使用常量“ServletActionContext.ACTION\u MAPPING”,而不是使用字符串“struts.actionMapping”。