What is the role of struts2

 

struts2 is a heavyweight frame, located in the Controller MVC architecture, it can be analyzed, for receiving page information which is then passed through internal processing, and returns the result.

Meanwhile struts2 also a MVC web framework layer, then what is the MVC struts2 it?

We can think about the use of struts2 process, we need to pass through the filter, call the URL to use to determine which Action, Action and then decide to return the results, and then submit the request. This constitutes a so MVC architecture, a filter (Controller) controls the selection operation of Action (Model), to obtain the results Result (View), submit a request to the controller.

So from a macro perspective, architecture, struts2 is to contact the Model and the View layer, according to user requirements to perform business logic and returns the result.

Briefly summarize its role is simply that the transmission parameters, sends the request to the appropriate controller, the controller calls the service interface, the final result will be returned back to the service interfaces specified view.

Having said that, however, we have not seen Youyuezhichu struts2, so why should we choose him as the control layer it? Here we need to know, before the emergence of struts2 framework, we use sevlet to operate, that is struts2 eliminate the servlet, so let's do a comparison.

Our three aspects to compare:

① configuration: When we configure the servlet, we need to configure in web.xml many, that we need to configure a servlet piece of code, this will not only lead to the web.xml code is too many, and not conducive to the development group , the need to manually configure two URL-PATTERN.

And when using struts2 of a good solution to this problem, we refer to a special XML files, configuration package properties and action attributes, which greatly increases the readability of the configuration code, and the clear structure level, to enhance the efficiency of group development .

② test: When we need to test our code, we have to use the servlet configuration parameters associated with the two vessels, HttpServletResponse and HttpServletRequest, which would increase our workload, but it can be a good struts2 independently unit test.

③ pass parameters: Each parameter passing of time, we must use the servlet manual operation scope, if serlvet method under a lot of circumstances, it will greatly influence the development, in struts2, we default filter stack It comes with a method for automatically closing argument, which greatly facilitated our development.

In fact, struts2 other aspects also have great advantages, such as global unusual configuration settings such as interceptors, such as ...

Use a brief summary of the process:

① introducing jar package

② core filter configuration

③ create Action, arranged to write code and returns the value

④ Configuration Profiles

Struts2 sum up the benefits:

struts2 application will be layered, clear product structure, can reduce the amount of code maintenance, while enabling developers to implement hierarchical, meaning that Java programmers can only focus on business logic implementation

Open source project, easy to use and expand

It provides a powerful global exception handling mechanism;

Result page navigation mode by Result easily label and page redirection jump;

Traffic class is scheduled by a simple, centralized configuration, and such modifications are very easy to configure;

It provides a simple, unified expression language to access all the available data access (OGNL);

Standard, strong authentication framework and international framework;

Offers a variety of technical support and page tags presentation layer, greatly simplify development;

Has a simple plug-in, just put the jar package response, anyone can extend Struts2 framework, such as:

Custom interceptors, result type custom, custom labels, custom functions needed for the Struts2 does not require any special configuration, and can be published for others to use.
With intelligent default settings, no additional cumbersome setup. Use the default settings to complete most of the program development projects required functionality.

Guess you like

Origin www.cnblogs.com/mark5/p/11652559.html