我试图了解 ActionMappingParametersInteceptor
类在 Struts2 中的使用。
查看 API:
This interceptor sets all parameters from the action mapping, for this request, on the value stack. It operates exactly like
ParametersInterceptor
, only the parameters come from theActionMapping
, not theActionContext.getParameters()
method.
ActionMapping
类是否包含与我从 ActionContext.getParameters()
获取的请求参数集不同的请求参数集?
拦截器的 struts defaultStack
似乎首先调用 ParametersInterceptor
,然后调用 ActionMappingParametersInteceptor
,但我看不出有任何理由这样做那个。
最佳答案
实际上,扩展 params
拦截器的 actionMappingParams
正在使用两个被覆盖且应该被覆盖的方法处理来自 action map 的参数:retrieveParameters
和 addParametersToContext
。第一个方法真正使用 ActionMapping
参数。第二个是将额外参数添加到操作上下文。
In this class this is a no-op, since the parameters were fetched from the same location. In subclasses both
retrieveParameters()
andaddParametersToContext()
should be overridden.
“no-op”意味着直到
The best way to add behavior to this interceptor is to utilize the
ParameterNameAware
interface in your actions. However, if you wish to apply a global rule that isn't implemented in your action, then you could extend this interceptor and override theParametersInterceptor.acceptableName(String)
method.
参数名称感知:
This interface is implemented by actions that want to declare acceptable parameters. Works in conjunction with
ParametersInterceptor
. For example, actions may want to create a whitelist of parameters they will accept or a blacklist of paramters they will reject to prevent clients from setting other unexpected (and possibly dangerous) parameters.
这是唯一可以将额外参数添加到操作上下文的情况。
关于java - ActionMappingParametersInteceptor - 为什么我需要它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15321188/