在 struts2 中使用扩展拦截器不适用于操作参数

发布于 2024-09-06 06:38:18 字数 596 浏览 2 评论 0原文

我有一个带有拦截器配置的默认包,并且我将该包扩展为另一个包并调用相同的拦截器

<action name="availability**">
            <param name="subTab">availability</param>
            <interceptor-ref name="tabStack"/>          
            <result>/WEB-INF/jsp/index.jsp?include=visibilit/availability.jsp</result>                      
        </action>

问题是在我的拦截器代码中没有读取参数:

Map params = invocation.getInvocationContext().getParameters();
subTab = params.get("subTab").toString(); //NULL exception

知道如何将参数传递给扩展拦截器?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卷耳 2024-09-13 06:38:18

您调用的 getParameters() 方法仅返回 HTTP 请求中的参数。 struts.xml 中设置的参数称为“静态参数”,您可以像这样访问它们(在拦截()方法中):

ActionConfig config = invocation.getProxy().getConfig();
Map<String, String> parameters = config.getParams();
String subTab = params.get("subTab");

来源:StaticParametersInterceptor.java

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

晚风撩人 2024-09-13 06:38:18

你能尝试一下这个语法吗?

<action name="availability**">
<interceptor-ref name="tabStack">
     <param name="subTab">availability</param>
</interceptor-ref>
</action>

我不确定,但也许这会起作用

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文