Struts 2 Acceptable Parameter's Names

岁酱吖の 提交于 2020-01-14 04:52:06

问题


In order to take control of the parameters which an action accept you must:

Make your action implement ParameterNameAware like:

public class sample implements ParameterNameAware(){

    public boolean acceptableParameterName(String parameterName) {  
       if (("amount".equals(parameterName) || 
            "sourceAccount".equals(parameterName) ||
            "destinationAccount".equals(parameterName))
            return true;
        else
           return false;
    }

}  

This method is called for the excluded properties of param properties.

So, you need to configure params interceptor to exclude all parameters, so the acceptableParameters get the chance to be called by params interceptor.

<interceptor-ref name="params">
    <param name="excludeParams">\w+((\.\w+)|(\[\d+\])|(\(\d+\))|(\['\w+'\])|(\('\w+'\)))*</param>
</interceptor-ref>

Am I correct?! This seems some how strange for me (Excluding all parameters and then adding them in each action).


回答1:


The Struts2 params interceptor behavior against accepting or declining parameters could be extended via the ParameterNameAware action. All parameters are handled by this interceptor if they are accepted or ignored if they are excluded. The extension point checks for accepted parameters. If they are accepted by the interceptor then they are passed, nevertheless additional checks is performed by calling acceptableParameterName but it useless if parameter is accepted by the interceptor. On the other hand if parameter is excluded by the interceptor then calling this method makes a power. Coexisting both methods looks strange because they are designed to be mutually exclusive.



来源:https://stackoverflow.com/questions/20254142/struts-2-acceptable-parameters-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!