Struts began in March 2000, 1.0 was released in July 2001. The Struts can develop an application architecture based on MODEL-View-Controller design mode. The MVC design mode divides a system into three mutual coordinated parts:
MODEL (model)
Model for the status of package system
View (view)
It is a representation of the model to provide a user interaction interface. When the model state changes, the view should be notified to update the view.
Controller
Accept request from the view and modify the status of the model.
You need to solve a problem in a JSP / Servlet-based web app. We know, the bottom layer of HTTP is a TCP / IP protocol, and TCP / IP is a stateless connection protocol, then if our model changes, there is no notification view. The Struts uses MVC Model 2 mentioned in JSP Specification V0.92, which is a revision of the MVC applied to the web. The illustration is as follows:
Chart 1: MVC Model 2 (from malcolm davis)
The Struts application has 3 main components: a servlet controller (provided by Struts, org.apache.action.actionServlet, hereinafter referred to as Controller) and the base class responsible for specific business processing (ORG.APache.Action.Action); JSP Page (Viewer); Applicable Business Logic Package (Model). Struts's central controller (ActionServlet) accepts all requests from the client, and requests the HTTP request to other Action objects according to the system configuration (Struts-config.xml) routing the other Action object (the child of Org.apache.Struts.Action.Action realized by the developer Class), all business operations are performed in these Action objects, such as inserting a single order, modify a record. After processing, the ActionServlet of Struts is turned to the JSP page, and the processing result is returned to the client. From here you can see that ActionServlets in Struts are important roles, which control all program flows, is the three relatively independent partial coordination work of MVC, providing systematic improvement. It can be seen from the following figure, Struts is a typical application of MVC MODEL 2.
Chart 2: Struts Working Mechanism (From Malcolm Davis)
When Struts is started, Controller reads a configuration file struts-config.xml, which defines the URL of the front-end request and the corresponding Action class and the mapping relationship of the FORM class used. The following is a snap in struts-config.xml. :
"/ logon" TYPE = "org.apache.struts.Webapp.example.logonaction" Name = "logonform" SCOPE = "reest" INPUT = "/logon.jsp"> action> As can be seen, this action will respond to the URL similar to / logon request (after we will see later, the actual URL here should be configured in Web.xml, such as /logon.do or /logon.other The suffixed URL is responsible for handling the Action class of this request is org.apache.struts.Webapp.Example.logonAction, the FORMBEAN used is logonform, Scope defines the range of this FORMBEAN exists only in the current Request existing in the current REQUEST . Struts will read these settings to generate the corresponding org.apache.Action.ActionMApping object. Controller is using these mapping to forward HTTP requests to the application's Actions. An actionmapping designated An attribute required to request a class (subclass of Action) corresponding to the URI For a DB application, A business logic bean is used to connect, query the database this bean returns the result to the Action Action to store these results into the REQUEST's FORM BEAN JSP display The next chapter discusses the ActionServlets playing a central controller in Struts.