Struts 2 Action

Action-

For struts based application we need to create action which will do the request processing and having business logic.

-> It can be a simple class implementing execute method.

Example:

	package com.javasafari;  
	public class Test {  
	public String execute(){  
		return "success";  
	}  
	} 

-> It can be a class implementing Action interface and implementing execute method.

Action interface provide some constant mentioned below:

  SUCCESS means that action execution is successful.

  ERROR means that action execution is failed.

  LOGIN means that user is not logged-in.

  INPUT means that validation is failed.

  NONE means that action execution is successful but no result will be displayed to the user.

Example:

    package com.javasafari;  
    import com.opensymphony.xwork2.Action;  
    public class Test implements Action{  
    public String execute(){  
        return SUCCESS;  
    }  
    }  

-> We can also create action by extending ActionSupport class.

We can use this method of creating action as this class implements other interfaces like Validateable,ValidationAware,TextProvider,Localization etc.

Example:

    package com.javasafari;  
    import com.opensymphony.xwork2.ActionSupport;  
    public class Test extends ActionSupport{  
    public String execute(){  
        return SUCCESS;  
    }  
    }

For every action we have to specify in web.xml:

<action name="test" class="com.javasafari.Test" 
                               method="execute">
    <result name="success">/Output.jsp</result>
</action>