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.Action class has two execute methods ,one HTTP specific and the other protocol independent.The HTTP based execute method has following parameters:
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");
}
}
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.
0 comments :
Post a Comment