0

I am moving from struts1 to struts2 and I have successfully created simple applications in struts2 I want to use unspecified / custom functions of Dispatchaction class which i used in struts1 in struts2 , which class would be extended to do this

2 Answers 2

1

No class would be extended; use the "method" attribute in the action configuration, or annotate the method directly if using annotation-based configuration. 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.

1

DispatchAction helps us in grouping a set of related functions into a single action. In Struts 2 all the Actions by default provide this functionality. 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.

for e.g 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;
    }
}
1
  • In struts1 we used <action path="/some action" type="mpackage.com.someclass" name="SubscriptionsForm" scope="request" parameter="perform"> By parameter 'perform' we tell server to call specific function How can we do this in struts2
    – Raheel
    Sep 13, 2012 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.