简体   繁体   English

struts2中DispatchAction类的替代方法

[英]Alternative of DispatchAction class in struts2

我从struts1移动到struts2并且我已经在struts2中成功创建了简单的应用程序我想使用Dispatchaction类的未指定/自定义函数,我在struts2中的struts1中使用它,该类将被扩展为执行此操作

No class would be extended; 不会延长课程; use the "method" attribute in the action configuration , or annotate the method directly if using annotation-based configuration. 在操作配置中使用“method”属性 ,或者如果使用基于注释的配置 ,则直接注释方法。 You can also use wildcard actions to avoid manual configuration. 您还可以使用通配符操作来避免手动配置。

If that doesn't work for you, please explain specifically what your needs are, and why that won't work. 如果这对您不起作用,请具体说明您的需求,以及为什么不起作用。

DispatchAction helps us in grouping a set of related functions into a single action. DispatchAction帮助我们将一组相关函数分组到一个操作中。 In Struts 2 all the Actions by default provide this functionality. 在Struts 2中,默认情况下所有Actions都提供此功能。 To use this functionality we need to create different methods with the similar signature of the execute() method, only the name of the method changes. 要使用此功能,我们需要使用execute()方法的类似签名创建不同的方法,只更改方法的名称。

for eg you can create a Action for User handling which includes method like create,delete update user etc 例如,您可以创建一个用户处理操作,其中包括创建,删除更新用户等方法

public class UserAction extends ActionSupport{

    private String methodName;

    public String execute()
    {
        methodName= "Inside execute method";
        return SUCCESS;
    }

    public String add()
    {
        methodName= "Inside add method";
        return SUCCESS;
    }

    public String update()
    {
        methodName= "Inside update method";
        return SUCCESS;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM