understanding struts action class

Upload: redankaiahu

Post on 30-May-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Understanding Struts Action Class

    1/3

    Understanding Struts Action ClassIn this lesson I will show you how to use Struts Action Class and forward a jsp filethrough it.

    What is 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 inteface tothe application's Model layer. It acts as glue between the View and Model layer. It alsotransfers the data from the view layer to the specific business process layer and finallyreturns the procssed data from business layer to the view layer.

    An Action works as an adapter between the contents of an incoming HTTP request andthe business logic that corresponds to it. Then the struts controller (ActionServlet) slects

    an appropriate Action and creates an instance if necessary, and finally calls executemethod.

    To use the Action, we need to Subclass and overwrite the execute() method. In theAction Class don't add the business process logic, instead move the database and business

    process logic to the process or dao layer.

    The ActionServlet (commad) passes the parameterized class to Action Form using theexecute() method. 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.

    Developing our Action Class?

    Our Action class (TestAction.java) is simple class that only forwards the TestAction.jsp.Our Action class returns the ActionForward called "testAction", which is defined in thestruts-config.xml file (action mapping is show later in this page). Here is code of our Action Class:

    TestAction.java

    package roseindia.net;

    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;

    http://www.roseindia.net/struts/understandingstruts_action_class.shtmlhttp://www.roseindia.net/struts/understandingstruts_action_class.shtmlhttp://www.roseindia.net/struts/understandingstruts_action_class.shtmlhttp://www.roseindia.net/struts/understandingstruts_action_class.shtml
  • 8/9/2019 Understanding Struts Action Class

    2/3

  • 8/9/2019 Understanding Struts Action Class

    3/3