user2331417
user2331417

Reputation: 19

Managing different methods for single action in struts 2

I am working on an application which is accessed using sub-domain. There are unique sub-domain for each client. In some cases I need different logic for different clients for eg file upload.

Can I configure in struts 2 such a way that with same action name I can call or redirect different methods in same action class ?

Upvotes: 0

Views: 516

Answers (1)

Niru
Niru

Reputation: 489

In struts 2 you can have different packages, methods but action URL can not be same.

Example:

    class UserAction extends ActionSupport
    {
     public String execute() throws Exception {
            return SUCCESS;
        }

     public string doDel() {
            return SUCCESS; 
            }
         public string doMod() {
            return SUCCESS;
        }
      }

In struts.xml

 <action name="*User" class="UserAction" method="{0}">
<result name="success">/User.jsp</result>
    </action>

Now your actions will be as follows:

User - call execute method.
doModUser - call doModUser method.
doDelUser - call doDelUser method.

In your case you can do like this, send parameter to identify method and based on which call the relevant method.

Upvotes: 1

Related Questions