About struts2

struts2 is one of Java Web framework technology based on MVC design pattern, struts2 framework in accordance with the MVC design ideas into the Java Web application layer control, including core and traffic controller controller FilterDispatcher Action, the model layer, including business logic components and database access components, view layer, including HTML, JSP, struts2 labels.

1, struts2 controller assembly

In the MVC-based application development, the main function of the controller components is to receive data from the client, call model (JavaBean) for data processing and customer decides to return to a view. struts2 controller main core business controller and controller FilterDispatcher Action.

1) FilterDispatcher controller

Core controller needs to load a Web-based application in the Java Web MVC framework, struts2 framework needs to be loaded is FilterDispatcher. FilterDispatcher is a filter, the core is struts2 controller controls the flow of operations and data across Java Web project. FilterDispatcher need to be configured in web.xml. In addition to configuring a core controller FilterDispatcher web.xml configuration file, the operation control data struts2, also need to use the struts.xml struts2 of another profile.

2) struts.xml profile

struts2 core configuration file is struts.xml. After the user requests submitted to the central controller FilterDispatcher, which business is done specifically by the Action Controller is pre-configured profile in struts.xml good, according to the data in the configuration file struts.xml, call a specific core controller FilterDispatcher Action to complete the service controller processing data, the data processing after processing result back to the central controller via FilterDispatcher other objects, the core controller determines the next operation struts.xml profile configuration.

3) Action Controller

Action is struts2 business controller, you can not implement any interface or class does not inherit any struts2. Action class is a Java class basic with high reusability. Action does not implement any business logic, business logic is only responsible for organizing the scheduling model components. Action class is a completely simple Java objects, with good code reuse. Action Servlet class associated with the API without, reducing the degree of coupling and Servlet, the application and testing is relatively simple. Action category execute () method returns a string only as a processing result, the processing results can be transmitted to another view or any Action.

2, struts2 model components

Model component is business logic modules may be implemented, in the actual development of the project, and the definition of the difference between the model of the component is more ambiguous, actually departing from the scope struts2 frame. struts2 frame service controller requests the user will not substantial processing user requests by the model component is responsible for the final processing, the processing only provides service controller case, the scheduler is responsible for scheduling model components. Different developers have different ways to write the model components, the purpose is to use the framework struts2 Action to call the model components.

Action controller saves data from the page, there is an execute () method in the Action Controller can invoke the business logic components to complete processing of the data in this method, the result of the process is to return a string, also known as a logical view in struts2.xml configuration file is correspondence between the actual and the logical view of the physical view. Traffic controller can be achieved by calling the business logic method creates an instance of the component model, usually, when traffic controller required to obtain a business component instance, will not get the business logic component instance directly, but to get the business model through the factory examples of the component, or other business manage instances Ioc container assembly.
----------------
Original link: https: //blog.csdn.net/weixin_40544356/article/details/81075755

Guess you like

Origin www.cnblogs.com/wangju/p/11903500.html