警告:参数与已接受的模式不匹配

时间:2021-03-28 18:05:54

I'm using Struts2.3.28. When I submit a form which uses the submit tag with the method attribute, I'm getting this warning:

我用Struts2.3.28。当我提交一个使用带有method属性的submit标记的表单时,我得到了这个警告:

WARN  com.opensymphony.xwork2.interceptor.ParametersInterceptor 
     warn- Parameter [method:save] didn't match accepted 
     pattern [[\w+((\.\w+)|(\[\d+\])|(\(\d+\))|
     (\['(\w|[\u4e00-\u9fa5])+'\])|(\('(\w|[\u4e00-\u9fa5])+'\)))*]]!

I have struts.enable.DynamicMethodInvocation set to true.

我有struts.enable。DynamicMethodInvocation设置为true。

I think this acceptParamNames property for the ParametersInterceptor (sort of a whitelist, it seems) was added in some recent version... The docs only says (basically)

我认为这个acceptParamNames属性对于ParametersInterceptor(看起来有点像白名单)是在最近的版本中添加的……医生只说(基本上)

"don't touch this" .

“不要碰这个”。

Great! So, what am I supposed to do if I still want to use the method attribute of submit tag?

太棒了!那么,如果我还想使用submit tag的method属性,我该怎么做呢?

Further: it's not clear for me the implications of this warning. If the pattern does not match neither the whitelist (acceptParamNames) nor the blacklist (excludeParams) (ah, the consistency), what is supposed to happen?

更进一步:我不清楚这个警告的含义。如果模式既不匹配白名单(接受参数)也不匹配黑名单(排除参数)(啊哈,一致性),应该发生什么?

1 个解决方案

#1


1  

It's a developer notification that is invoked from the method

它是一个从方法调用的开发人员通知

 protected boolean isAccepted(String paramName) {
        AcceptedPatternsChecker.IsAccepted result = acceptedPatterns.isAccepted(paramName);
        if (result.isAccepted()) {
            return true;
        }
        notifyDeveloper("Parameter [#0] didn't match accepted pattern [#1]!", paramName, result.getAcceptedPattern());
        return false;
    }

it means that if the parameter name matches the list of accepted patterns, then it's passed by this interceptor (after checks for name length, and if it's not excluded).

这意味着,如果参数名称与已接受的模式列表相匹配,那么它将被这个拦截器传递(在检查名称长度之后,如果它没有被排除)。

New interceptor also checks the acceptance of the parameter value.

新的拦截器还检查对参数值的接受程度。

The whitelist and blacklist of parameters are managed by the ParameterNameAware action separately.

参数的白名单和黑名单分别由ParameterNameAware操作管理。

Note:

注意:

Using ParameterNameAware could be dangerous as ParameterNameAware#acceptableParameterName(String) takes precedence over ParametersInterceptor which means if ParametersInterceptor excluded given parameter name you can accept it with ParameterNameAware#acceptableParameterName(String).

使用ParameterNameAware可能会很危险,因为ParameterNameAware#acceptableParameterName(String)优先于ParametersInterceptor,这意味着如果参数拦截器不包含给定的参数名称,那么您可以使用ParameterNameAware#acceptableParameterName(String)接受它。


The default list of patterns are settled during initialization (it's hardcoded using default constant value), so if you didn't use a parameter acceptParamNames in the interceptor configuration, Struts will use its default pattern list. But you can override the parameter value by specifying this parameter to the parameters interceptor.

默认模式列表是在初始化过程中确定的(使用默认常量值对其进行硬编码),因此如果在拦截器配置中不使用参数acceptParamNames, Struts将使用它的默认模式列表。但是您可以通过将这个参数指定给参数拦截器来重写参数值。

Note: The method notifyDeveloper should only print in devMode, otherwise it prints only in DEBUG mode of the logger. You can also trace massages by changing a logger level to TRACE.

注意:notifyDeveloper方法只能在devMode下打印,否则只能在日志记录器的调试模式下打印。您还可以通过将日志记录器级别更改为trace来跟踪按摩。


To use a method attribute of the submit tag you should:

要使用提交标记的方法属性,您应该:

  1. Enable DMI:
  2. 启用DMI:
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>

2. Override the list of excluded patterns. the default list of exluded patterns contains a pattern that excludes method: parameter (and action: too). That is also mentioned by AleksandrM in the comment.

2。覆盖排除的模式列表。exluded模式的默认列表包含一个不包含方法的模式:参数(和操作:too)。AleksandrM在评论中也提到了这一点。

For more information see documentation for params interceptor.

有关更多信息,请参阅params拦截器的文档。

#1


1  

It's a developer notification that is invoked from the method

它是一个从方法调用的开发人员通知

 protected boolean isAccepted(String paramName) {
        AcceptedPatternsChecker.IsAccepted result = acceptedPatterns.isAccepted(paramName);
        if (result.isAccepted()) {
            return true;
        }
        notifyDeveloper("Parameter [#0] didn't match accepted pattern [#1]!", paramName, result.getAcceptedPattern());
        return false;
    }

it means that if the parameter name matches the list of accepted patterns, then it's passed by this interceptor (after checks for name length, and if it's not excluded).

这意味着,如果参数名称与已接受的模式列表相匹配,那么它将被这个拦截器传递(在检查名称长度之后,如果它没有被排除)。

New interceptor also checks the acceptance of the parameter value.

新的拦截器还检查对参数值的接受程度。

The whitelist and blacklist of parameters are managed by the ParameterNameAware action separately.

参数的白名单和黑名单分别由ParameterNameAware操作管理。

Note:

注意:

Using ParameterNameAware could be dangerous as ParameterNameAware#acceptableParameterName(String) takes precedence over ParametersInterceptor which means if ParametersInterceptor excluded given parameter name you can accept it with ParameterNameAware#acceptableParameterName(String).

使用ParameterNameAware可能会很危险,因为ParameterNameAware#acceptableParameterName(String)优先于ParametersInterceptor,这意味着如果参数拦截器不包含给定的参数名称,那么您可以使用ParameterNameAware#acceptableParameterName(String)接受它。


The default list of patterns are settled during initialization (it's hardcoded using default constant value), so if you didn't use a parameter acceptParamNames in the interceptor configuration, Struts will use its default pattern list. But you can override the parameter value by specifying this parameter to the parameters interceptor.

默认模式列表是在初始化过程中确定的(使用默认常量值对其进行硬编码),因此如果在拦截器配置中不使用参数acceptParamNames, Struts将使用它的默认模式列表。但是您可以通过将这个参数指定给参数拦截器来重写参数值。

Note: The method notifyDeveloper should only print in devMode, otherwise it prints only in DEBUG mode of the logger. You can also trace massages by changing a logger level to TRACE.

注意:notifyDeveloper方法只能在devMode下打印,否则只能在日志记录器的调试模式下打印。您还可以通过将日志记录器级别更改为trace来跟踪按摩。


To use a method attribute of the submit tag you should:

要使用提交标记的方法属性,您应该:

  1. Enable DMI:
  2. 启用DMI:
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>

2. Override the list of excluded patterns. the default list of exluded patterns contains a pattern that excludes method: parameter (and action: too). That is also mentioned by AleksandrM in the comment.

2。覆盖排除的模式列表。exluded模式的默认列表包含一个不包含方法的模式:参数(和操作:too)。AleksandrM在评论中也提到了这一点。

For more information see documentation for params interceptor.

有关更多信息,请参阅params拦截器的文档。