In this post we will see the architecture of Struts 1 or work flow of popular mvc framework that is Struts 1. As we know struts 1 is a mvc (Model-View-Controller) based framework which reduces the work of developers to develop a web application. So, one question will come in your mind i.e. What are the elements in Struts 1 that serves as Model-View-Controller rolls ?
Here is the answer :
Model : Models in Struts 1 framework are the java bean classes that extends ActionForm class provided in Struts jars. Model classes holds the state of the internal and external system.
View : Views are web components that are shown to the web browser users. In Struts 1, it can be jsp page or any view render technique such as Tiles.
Controller : Controllers are the components that handles are the requests that comes from users and decides which view is to send back to the use as response. In Struts 1 the controller part is handled by ActionServlet class and a subclass of Action class that is developer defined. The controller may interact with the application specific business logic or some code that persists data in database or with an EJB.
The bellow figure shows the work flow of Struts 1 :
The following steps shows the work flow of Strust 1 framework :
1. When first time user request comes from the browser, ActionServlet invoked which reads struts-config.xml configuration file and creates configuration objects. struts-config.xml contains information about the FormBeans, that are subclasses of ActionForm, Actions and view that can be send as response to the browser.
2. In the second step ActionServlet instantiate the specified form bean and puts the value of the form attributes, submitted by the browser, to form bean.
3. Then ActionServlet calls the Action class’s execute method, which returns ActionForward instance. ActionForward instance contains the detail of the view to be return as response.
4. ActionServlet renders the view and return to the browser as response.