The difference between Struts2 and Struts1

Source: Internet
Author: User
Struts2 In fact is not a strange web framework, STRUTS2 is based on the webwork design thought as the core, absorbing the advantages of Struts1, so you can think Struts2 is the product of Struts1 and webwork combination.

In simple terms, the difference is:

One is Stuts1, one is Stuts2, this is the biggest difference, technical aspects, STUTS1 has a core controller, but only provides an interface, that is, execute, but also to configure Actionform and so on, very troublesome, so dependence is stronger While STUTS2 is developed for interceptors, the so-called AOP idea, can configure multiple actions, easy to use, but because the interceptor before the request has some injection operations, the speed relative to the Stuts1 slow.

A brief introduction of MVC
STRUTS2 is a compatible Struts1 and webwork MVC framework, and since the MVC framework is mentioned, you have to make a brief introduction to the MVC framework, which is limited to simple introductions, and if you want to learn more about MVC, you can view the relevant documentation. Or find a Struts1 book, I believe that the above about the length of MVC is not very small. In fact, the ultimate goal of Java's current frameworks is to contact coupling, either spring, Hibernate, or the MVC framework, which is intended to increase reuse for contact coupling. MVC is in touch with the coupling between view and model.
MVC consists of three basic parts: Model, view, and Controller, which work together with minimal coupling to increase the scalability and maintainability of the program. The implementation techniques of each part can be summarized as follows:
1) The Entitybean of Model:javabean and EJB
2) The taglib of view:jsp and struts
3) Controller:struts's Actionservlet, Action
To sum up, the advantages of MVC are mainly as follows:
1 multiple views can correspond to a model. According to MVC design pattern, a model corresponding to multiple views, can reduce code duplication and code maintenance, once the model changes, it is easy to maintain
2 The data returned by the model is separated from the display logic. Model data can be applied to any display technology, such as using JSP pages, velocity templates, or directly producing Excel documents
3 application is divided into three layers, reducing the coupling between the layers, providing the scalability of the application
4 The concept of the control layer is also very effective, because it combines different models and different views to complete different requests. Therefore, the control layer can be said to contain the concept of user request permission
5 MVC is more in line with the spirit of software engineering management. Different layers, each layer of components have the same characteristics, is conducive to the adoption of engineering and tooling to generate management program code
The concept of MVC is also nonsense to this, the key is the implementation of each module is what the technology respectively.
Ii. introduction of Struts2
Struts2 since the development from the STRUTS1, but in fact, Struts2 and Struts1 in the framework of the design of the idea is still very different, Struts2 is based on the design of WebWork as the core, Why Struts2 do not follow the design of Struts1, after all, Struts1 in the current enterprise applications or have a very large market in, then, to see some of the shortcomings of Struts1:
1 support of the presentation layer technology single
2 is heavily coupled with the Servlet API, which can be seen from the action's method declaration of Execute
3 code relies on the Struts1 API, intrusive, which can be seen from the Write action class and Formbean, action must implement struts action class
And the reason why Struts2 with webwork design thought as its core, is the recent webwork rise, then webwork no Struts1 above those shortcomings, more in line with MVC design ideas, also more conducive to the reuse of code.
Based on the above introduction can be seen, the STRUTS2 architecture and STRUTS1 architecture is very different, Struts1 is using Actionservlet as its central processor, Struts2 uses an interceptor (Filterdispatcher) as its central processor, one of the benefits of which is to separate the action class from the Servlet API.
STRUTS2 's simple processing process is as follows:
1) Browser Send request
2 The Center processor finds the corresponding action class for the processing request according to the Struts.xml file
3 WebWork's interceptor chain automatically applies common functions to requests, such as: WorkFlow, validation and other functions
4 If the method parameter is configured in the Struts.xml file, then the methods in the action class corresponding to the way parameter are invoked, otherwise the generic Execute method is invoked to handle the user request
5 respond to the browser the result returned by the corresponding method in the Action class
Three, Struts2 and Struts1 contrast
1 How the Action class is implemented:
The STRUTS1 action must extend the action class or the subclass of the action when it is implemented, and the Struts2 action class can be implemented without implementing any classes and interfaces, although STRUTS2 provides a Actionsupport class, but is not a necessity.
2 The Struts1 action class is a singleton pattern that must be designed to be thread-safe, Struts2 generates an instance for each request
3 The Struts1 action class relies on the servlet API, as can be seen from its Execute method signature, the Execute method has two servlet parameters HttpServletRequest and HttpServletResponse, Struts2 is not dependent on the servlet API
4 The STRUTS1 relies on the servlet API for these web elements, so it is difficult to test Struts1 's action, with the help of other test tools, Struts2 's action can be tested like other model-level service classes
5) Struts1 's action and view are transmitted through actionform or its subclasses, although there are lazyvalidationform such actionform, It is not possible to transmit data through a simple pojo, as other levels do, and STRUTS2 has turned this expectation into reality.
6) Struts1 bound Jstl, for the writing of the page to bring convenience, STRUTS2 integrated Ongl, can also use JSTL, therefore, Struts2 the expression of the language more powerful
Four, Struts2 and webwork contrast
Struts2 is actually WebWork2.3, but there is a slight difference between Struts2 and webwork:
1) Struts2 no longer supports the built-in IOC container, instead of the spring IOC container
        2) Struts2 the tag for some Ajax features of WebWork to replace it with dojo instead

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.