Header Ads

  • Breaking Now

    What are the methods in Action class?

    An Action class in the struts application extends Struts 'org.apache.struts.action.Action" class. Action class acts as wrapper around the business logic and provides an interface to the application's Model layer. Action class mediates between the View and Model layer in both directions it means it transfers data to and fro from the view layer and the specific business process layer.

    If you look at the sequence diagram, it gives you a correct picture how an Action class instance is invoked.When it is invoked then overridden execute() method is invoked.It is advisable not to put the business process logic inside execute method which should ideally have navigational logic details, instead move the database and business process logic to DAO layer.

    Struts Sequence Diagram

    The return type of the execute() method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object,mapping of which is provided in struts-config.xml file.

    package dpun.action;


    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;


    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;


    public class MyAction extends Action
    {
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm actionForm,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
    return mapping.findForward("myAction");
    }
    }
    Action class has two execute methods ,one HTTP specific and the other protocol independent.The HTTP based execute method has following parameters:
    ActionMapping mapping:This object is used to refer this instance.
    ActionForm actionForm:It refers ActionForm bean class associated with this request. HttpServletRequest request:It represents HTTP request.
    HttpServletResponse response:It represents HTTP response.

    While protocol independent execute has ServletRequest and ServletResponse instead of HttpServletRequest and HttpServletResponse parameters.

    No comments

    Post Top Ad

    Post Bottom Ad