Struts

What is Struts?

Struts Framework was developed by Craig McLanahan in 2002 and subsequently handed over to Apache Jakarta project group. Struts Framework is the implementation of Model-View-Controller (MVC) design pattern for the JSP and Servlets.
 
What is Model-View-Controller (MVC) ?
Model-View-Controller architecture is all about dividing application components into three different categories Model, View and the Controller. Components of the MVC architecture has unique responsibility and each component is independent of the other component.Changes in one component will have no or less impact on other component. 
    The main aim of the MVC architecture  is to separate the business logic and application data from the presentation data to the user.
 
Why MVC?
  • They are resuable : When the problems recurs, there is no need to invent a new solution, we just have to follow the pattern and adapt it as necessary.
  • They are expressive: By using the MVC design pattern our application becomes more expressive.
What are responsibilities of different components of MVC?
Model
  •  Model is responsible for providing the data from the database and saving the data into the data store. 
  • All the business logic are implemented in the Model. Data entered by the user through View are check in the model before saving into the database. Data access, Data validation and the data saving logic are part of Model.
  • The model object knows about all the data that need to be displayed. It is model who is aware about all the operations that can be applied to transform that object. It only represents the data of an application. 
  • The model represents enterprise data and the business rules that govern access to and updates of this data. Model is not aware about the presentation data and how that data will be displayed to the browser.
View
  • View represents the user view of the application and is responsible for taking the input from the user, dispatching the request to the controller and then receiving response from the controller and displaying the result to the user. HTML, JSPs, Custom Tag Libraries and Resources files are the part of view component.
  •  The view represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain the contents and renders it. 
  • The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we can say that it is the responsibility of the view to maintain the consistency in its presentation when the model changes.
Controller
  • Controller is intermediary between Model and View. Controller is responsible for receiving the request from client. Once request is received from client it executes the appropriate business logic from the Model and then produce the output to the user using the View component.
  •  ActionServlet, Action, ActionForm and struts-config.xml are the part of Controller.
  • Whenever the user sends a request for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. In  GUIs, the views and the controllers often work very closely together.
Rate this post

Leave a Reply