java - ActionMappingParametersInteceptor - 为什么我需要它

标签 java parameters struts2 interceptor

我试图了解 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 the ActionMapping, not the ActionContext.getParameters() method.

ActionMapping 类是否包含与我从 ActionContext.getParameters() 获取的请求参数集不同的请求参数集?

拦截器的 struts defaultStack 似乎首先调用 ParametersInterceptor,然后调用 ActionMappingParametersInteceptor,但我看不出有任何理由这样做那个。

最佳答案

实际上,扩展 params 拦截器的 actionMappingParams 正在使用两个被覆盖且应该被覆盖的方法处理来自 action map 的参数:retrieveParametersaddParametersToContext。第一个方法真正使用 ActionMapping 参数。第二个是将额外参数添加到操作上下文。

In this class this is a no-op, since the parameters were fetched from the same location. In subclasses both retrieveParameters() and addParametersToContext() 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 the ParametersInterceptor.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/

相关文章:

java - 如何允许用户选择要初始化的类

java - 文件名 "tfileInput"设置目录的根路径是什么?

dynamic - C#中的方法参数可以是动态的吗

MySQL 函数从查询传递参数

c# - 如何在 Select 语句的 IN 子句中提供一串 ID,即使该列是整数

java - 使用迭代器时如何获取 Struts 2 表单的所有键

java - 如何在 Kotlin 的 groupBy 中展平列表值列表

java - 如何阻止 Java 瘦客户端请求,直到 Ignite 集群中的数据预加载完成

java - Struts2 - 将重定向设置为 false

java - Struts 2选择带有数组列表值的标签