Java Tutorial - Java Script : A Struts Overview

Java Tutorial - Java Script :

A Struts Overview


To provide a very simple overview of how Struts works we will break down the MVC design pattern into the Struts components used for its implementation. This is done, as follows:

The controller. Handles the requests between the user (Web browser) and the application, executing the appropriate business logic and then invoking the appropriate view component to communicate the result of the user request. The primary component of the controller is a servlet that is subclassed from ActionServlet. The actions that will be performed by the ActionServlet are defined in a subclass of the Action class. These objects encapsulate the business logic, determine the outcome, and invoke the appropriate View component to create the response. The validation of form data is performed by subclassing the ActionForm class, once the ActionForm has successfully executed it’s validate method, the ActionForm, is passed on to the Action class. The contract or mapping between the ActionServlet and the Action class are defined by the ActionMappings, which are defined in /WEB-INF/strutsconfig. xml.

The model: Encapsulates the state of the system and the methods that change the state of the system. The classic example is that of the shopping cart, which contains properties that represent the current list of items the user has purchased. The beans expose methods that enable items to be added, deleted and processed for checkout. The Action object we discussed for the controller would be responsible for instantiating and invoking the methods of the bean.

The view: The view is most often constructed using JavaServer Pages in conjunction with the standard tag libraries or the custom tags that are  included with Struts. The tags are used to dynamically pull data from the model object into the view before it is presented to the user.