Struts 2可接受的参数名称 [英] Struts 2 Acceptable Parameter's Names

查看:135
本文介绍了Struts 2可接受的参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了控制您必须执行的操作的参数:

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

使您的操作实现 ParameterNameAware like:

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;
    }

}  

此方法对 param 属性的排除属性调用。

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

需要配置 params 拦截器以排除所有参数,因此 acceptableParameters params 拦截器。

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).

推荐答案

p>可以通过 ParameterNameAware 操作扩展Struts2 params 拦截器对接受或拒绝参数的行为。如果它们被排除,则它们被接受或忽略,所有参数由该拦截器处理。扩展点检查接受的参数。如果它们被拦截器接受,则它们被传递,但是通过调用 acceptableParameterName 来执行额外的检查,但是如果拦截器接受参数,则没有用。另一方面,如果参数被拦截器排除,那么调用这个方法会产生一个权力。共存两种方法看起来很奇怪,因为它们被设计为互斥的。

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.

这篇关于Struts 2可接受的参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆