Struts2 Introduction
Struts 2 framework as Struts 1. the replacement technology of the X framework is relative to Struts 1. X has essentially changed. The Struts 2 framework is developed from the WebWork framework. apache Struts 2 is a webwork2. with their respective development, the webwork and Struts communities have decided to merge the two into Struts 2. The new version of Struts is as easy to use as the previous version. To some extent, Struts2 does not inherit the lineage of Struts1, but inherits the lineage of webwork and absorbs the advantages of Struts1 and webwork. Therefore, Struts2 is not a new framework.
When talking about Struts, the mvc design pattern has to be discussed. The mvc design pattern is a widely used software design pattern. With the rapid development of network applications, applications become more and more complex. The mvc Design Pattern provides the most basic analysis method for the application model and provides a clear design framework for product construction, provide a standard basis for software engineering.
The mvc design mode divides applications into model layer, view layer, and controller.
The Model layer includes the business logic and data access layer. In the entire mvc Model, the Model part is the processing of business processes or States and the formulation of business rules, which can be said to be the most important part of mvc.
View: A web project may have many different views. The mvc design mode only allows you to collect and process view data and respond to user requests, it does not include the processing of business processes in the view.
The Controller serves as a bridge between the view layer and the business logic layer, and controls the data flow between the two. When a user requests data from Part V to the Controller, the Controller calls the corresponding model layer for processing in the controller. The Controller then forwards the processing result to the appropriate view layer to perform this process cyclically.
Mvc workflow:
1. Your request is submitted to the Controller.
2. After the Controller receives a user request, it calls the corresponding model (javabean or EJB) to process the user request according to the user's specific needs.
3. After the Controller calls the model layer for data processing, It redirects to another view or other control layer based on the processing results.
How struts2 works
Struts2 is one of the java web framework technologies based on the mvc design model. The Struts2 framework divides java web applications into control layers (core controllers and service controllers) according to the mvc design philosophy), model layer (business logic component and database access component), view layer (including HTML, JSP, Struts2 table signature ).
1. The customer submits a request to the server.
2. The request is submitted to a series of filters or interceptors, and finally to FilterDispather.
3. FilterDispather reads the configuration file struts. xml and calls an Action based on the configuration information to process customer requests.
4. After the Action is processed, return the result. FilterDispather finds the corresponding page Jump Based on the struts. xml configuration.
Core Controller
One of the factors for Struts2's success lies in the core controller FilterDispather, which runs as a filter in a java web project and is responsible for intercepting all user requests. When user requests arrive, the filter request filters user requests. FilterDispather is responsible for four functions:
(1) execute Actions
(2) Clear ActionContext
(3) maintain static content
(4) Clear the interceptors of XWork within the request Lifecycle
Business Controller
Another factor for Struts2's success is the Action business logic controller. When developing a java web application project based on Struts2, Action is the core of Data Processing. A large number of Action classes need to be compiled and the Action is configured in the struts. xml file. The Action class contains the processing logic for user requests. Therefore, the Action is also called the Action Service controller. It serves as a bridge between user requests and business logic. Each Action acts as the customer's business proxy.
Summary
Struts2 closely centers around the two core controllers, the request is forwarded to the appropriate controller based on the request parameters, the service interface is called in the controller, and the results returned by the service interface are packaged and sent to the specified view, the display of processing results is completed by the view, which makes the development modular, reduces coupling, and easier to expand. Of course, the detailed advantages of Struts2 are worth noting, for example, getting the Form Content, generating parameter objects, and easily expanding the plug-in mechanism.