简体   繁体   中英

How do you obtain the value of struts.action.extension in a struts2 interceptor?

I need to access the struts.action.extension value in the struts.xml file from an interceptor. Any suggestions?

I realize the answer is probably for a previous version of struts, it did not work in the version of struts I'm using (struts v2.2). The following did work, though...

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

... where ActionMapping is org.apache.struts2.dispatcher.mapper.ActionMapping.

Thought it might help someone.

Thanks to Musachy Barroso over on the Struts User list I added the following to my interceptor:

/**
 * @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;
}

as Wes Wannemacher notes on the same list this in't actually supported but is extremely unlikely to change in future releases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM