When we deploy our application in the server, at first the container reads the information from web.xml file.Here ActionServlet object will be created and init() of ActionServlet will be called.Here ActionServlet is the backbone to the whole application.
When client send a rewuest using .jsp extension , getters() and reset() of FormBean will be called. When client fill the form and press on submit button, then setters() and validate() will be called. If the data is not valid ,then the form redirects to another page which is specified in struts-config.xml file. If the data is valid , then only Action class object will be created.
In Action class , have execute() which have return type of ActionForward. We can specify the business logic in Model and provide that object in execute(). After completion of business logic execution , then it forwards to another page ( either success or failure) , whichis specified in struts-config.xml file.
A client requests a path that matches the Action URI pattern.The container passes the request to the ActionServlet.If this is a modular application the ActionServlet selects the appropriate module.The ActionServlet looks up the mapping for the path.If the mapping specifies a form bean the ActionServlet sees if there is one already or creates one.If a form bean is in play the ActionServlet resets and populates it from the HTTP request.If the mapping has the validate property set to true it calls validate on the form bean.If it fails the servlet forwards to the path specified by the input property and this control flow ends.If the mapping specifies an Action type it is reused if it already exists or instantiated.The Action s perform or execute method is called and passed the instantiated form bean (or null).The Action may populate the form bean call business objects and do whatever else is needed. The Action returns an ActionForward to the ActionServlet.If the ActionForward is to another Action URI we begin again; otherwise it s off to a display page or some other resource. Most often it is a JSP in which case Jasper or the equivalent (not Struts) renders the page.
Flow:: 1) Action servlet gets the request.It initiates the servlet-config.xml and selects an appropriate page as per the mapping 2)If the accessed file is .java it does the appropriate action and fwd it to the file specified in the strus-config.xml. If the accessed path is .jsp it invokes the action bean where in the validation for the user input is done if it fails errors are displayed..if it succeeds the action servlet is kicked and does the steps in execute() method..and fwd it to the necessary page as in mappings.foward()
The Struts Flow is like this the very first request comes to the Action servlet which the part of the Controller component of the MVC architeture then the requets is disptachted to the request processor the request processor find the specified mapping url of the response in invoke the page.
The struts config.xml use to define as the mapping from the pages.After finding the respective mapping the bean is populated if its their and the forward to the requested path.
When we deploy our application in the server at first the container reads the information from web.xml file.Here ActionServlet object will be created and init() of ActionServlet will be called.Here ActionServlet is the backbone to the whole application.
When client send a rewuest using .jsp extension getters() and reset() of FormBean will be called. When client fill the form and press on submit button then setters() and validate() will be called. If the data is not valid then the form redirects to another page which is specified in struts-config.xml file. If the data is valid then only Action class object will be created.
In Action class have execute() which have return type of ActionForward. We can specify the business logic in Model and provide that object in execute(). After completion of business logic execution then it forwards to another page ( either success or failure) whichis specified in struts-config.xml file.
1) When first the request is made from a JSP/HTML/XSLT to the server with a particular URI(/something.do) the controll first reaches Web.xml file.
2) it checks the mapping for /something.do in web.xml and finds the ActionServlet and loads ActionServlet. ...... <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> .....
3) As part of loading ActionServlet calls the init() as every other servlet does. (Note: ActionServlet extends HttpServlet only) ...................... <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> ........................
4) in init() it takes the init-parameters as struts-config.xml and loads the xml file.
5) then the ActionServlet calls the proceed() of RequestProcessor class.
6) in proceed() it checks the appropriate mapping for current request creates and ActionMapping object and maps the URI to the action in the struts-config.xml.
7) then it creates an object to ActionForm associated to that action mapped object
8) calls the setters and reset().
9) if the action tag in struts-config.xml contains validate "true" then the validate method is called.
10) if any validation errors it return to view component (any jsp XSLT) which is specified as an attribute of input "/error.jsp"
11) if there are not validation errors it then creates an Action class for that mapping and search for execute method and executes it.
12) execute method performs the bussinesslogic which you provide and returns with an ActionForward key.
13) now the returned key is searched in the mapping object which is specified as forward tag.
14) it looks for the appropriate view component and performs the getters on that view component and returns the response to the browser.