Using an extended interceptor in struts2 does not work w/ action parameters

扶醉桌前 提交于 2019-12-24 19:51:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!