问题
I have a default package w/ an interceptor configure, and i'm extending that package into another one and calling the same interceptor
<action name="availability**">
<param name="subTab">availability</param>
<interceptor-ref name="tabStack"/>
<result>/WEB-INF/jsp/index.jsp?include=visibilit/availability.jsp</result>
</action>
The problem is that the param is not being read inside my interceptor code:
Map params = invocation.getInvocationContext().getParameters();
subTab = params.get("subTab").toString(); //NULL exception
Any idea how i can pass parameters to extended interceptors?
Thanks!
回答1:
The getParameters() method which you are calling only returns the parameters from the HTTP request. The parameters set in struts.xml with are called "static parameters", and you can access them (within the intercept() method) like this:
ActionConfig config = invocation.getProxy().getConfig();
Map<String, String> parameters = config.getParams();
String subTab = params.get("subTab");
Source: StaticParametersInterceptor.java
回答2:
Can you try this syntax
<action name="availability**">
<interceptor-ref name="tabStack">
<param name="subTab">availability</param>
</interceptor-ref>
</action>
I am not sure but maybe this will work
来源:https://stackoverflow.com/questions/3067071/using-an-extended-interceptor-in-struts2-does-not-work-w-action-parameters