问题描述
我有以下动作映射
我可以使用 Interceptor 中的以下行获取参数映射
I can get parameter map using following line in Interceptor
如上,有没有办法获取拦截器参数,如下映射中定义的那样.
Just as above, is there any way to get interceptor parameters as defined in following mapping.
动作参数的定义方式如下,动作参数和拦截器参数应该分开访问.
And action parameters are defined in following way, action parameters and interceptor parameters should be accessible separately.
请注意,我不想将拦截器中的参数字段声明为
Please note that I don't want to declare parameter fields in my interceptor as
<小时>
在 Dev Blanked 的回答之后,我实施了他的技术.它没有用,所以我在这里分享我的代码.我正在使用 Struts 2.3.1.2.
After Dev Blanked's asnwer, I implemented his technique. It did not work so I am sharing my code here. I am using Struts 2.3.1.2.
库
- asm-3.3.jar
- asm-commons-3.3.jar
- asm-tree-3.3.jar
- commons-fileupload-1.2.2.jar
- commons-io-2.0.1.jar
- commons-lang-2.5.jar
- freemarker-2.3.18.jar
- javassist-3.11.0.GA.jar
- ognl-3.0.4.jar
- struts2-core-2.3.1.2.jar
- xwork-core-2.3.1.2.jar
Struts.xml
拦截器
控制台输出,当 theAction
被点击时.
推荐答案
在您的自定义拦截器中,您可以定义如下图
In your custom interceptor you can define a map like below
然后在您的动作映射中,您可以传入如下参数 .. 这些将存储在拦截器的映射中
Then in your action mappings you can pass in parameters like below .. these will be stored in the map of the interceptor
"yourInterceptor" 是指你在将拦截器添加到 struts.xml 时给出的拦截器的名称.当像上面那样配置'interceptorConfigs'时,拦截器内的映射将有,键/值对.
"yourInterceptor" refers to the name of the interceptor you have given when adding your interceptor to the struts.xml. When configured like above 'interceptorConfigs' map inside the interceptor will have , key/value pairs.
如果您想让这些对您的操作可用,您只需将地图设置为 ActionContext
中的上下文变量.然后可以在操作中检索它.
If you want to make these available to your action, you can just set the map as a context variable in the ActionContext
. This can then be retrieved inside the action.
这篇关于在 Struts 2 中获取拦截器参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!