在struts2中使用扩展的拦截器无法通过操作参数使用 [英] Using an extended interceptor in struts2 does not work w/ action parameters

查看:74
本文介绍了在struts2中使用扩展的拦截器无法通过操作参数使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置了拦截器的默认程序包,我正在将该程序包扩展到另一个程序包中,并调用相同的拦截器

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?

谢谢!

推荐答案

您正在调用的getParameters()方法仅返回HTTP请求中的参数.在struts.xml中使用设置的参数称为静态参数",您可以按以下方式访问它们(在intercept()方法中):

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");

来源: StaticParametersInterceptor.java

这篇关于在struts2中使用扩展的拦截器无法通过操作参数使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆