Springmvc and Struts2 differences and comparison summary

Source: Internet
Author: User

(i) the framework

The following things are basically I paste from the Internet over, not so much patience and time a word of the knock, but the basic can show me the choice of springmvc ideas and reasons.


Put this picture here, I mean Springmvc and Struts2 are really different, although they have the same functional components as the core distributor (which is determined by the MVC pattern itself).

Why SPRINGMVC will win the final victory. Talk about some of my own views:

First, the MVC framework appears to map URLs from the HTTP world to the Java world, which is the core function of the MVC framework. And in the URL this point Springmvc undoubtedly more elegant.

Second, from the design realization point of view, I think springmvc more clear. Even if we compare Struts2 's schematics and Springmvc's class diagrams, it's still confusing, far from being springmvc more intuitive:

SPRINGMVC Design idea: Standardize the whole process process, and assign each processing step to a different component for processing.

This programme actually involves two aspects:

L Process Normalization-divides the processing process into several steps (tasks) and concatenates all the steps with a clear logical mainline

L Process Process assembly-defines each step (task) in the process process as an interface and assigns a different implementation pattern to each interface

Process normalization is the goal, and the process division and process definition are the means. Therefore, the primary content of process normalization is to consider the logical steps that a common servlet responder should include:

The L step 1--the HTTP request to find the corresponding Controller processing class (method)--handlermapping

The L step 2--calls the corresponding Controller processing class (method) to complete the business logic--handleradapter

The L step 3--handles exceptions that may occur when controller processes a class (method) Call--handlerexceptionresolver

The L Step 4--HTTP Response processing based on the result of the invocation of the Controller processing class (method)--viewresolver

It is this design based on component and interface that supports another feature of SPRINGMVC: scalability of behavior.

Third, the design principle is more clear.

"Open for extension/closed for modification"

This important design principle was written at the beginning of the SPRINGMVC chapter in spring's official reference: a key designs principle in Springweb MVC and in Spring in the "Op" En for extension, closed for modification "principle.

And the emphasis is well embodied in the implementation of SPRINGMVC, which can be extended, but not changed. I've expanded spring's IOC, AOP capabilities, and that SPRINGMVC should be in the same vein as spring.

Finally, the modular design and specific design principles allow SPRINGMVC to form a gathering. God--springmvc always runs along a fixed line of logic shape--SPRINGMVC has many different patterns of behavior

SPRINGMVC is a component-based development framework, the components of the different implementation system constitutes a "shape", the components of the logic series constitute the "God". Therefore, "the shape disperses the god not to scatter": The SPRINGMVC logic Main Line always does not change, but the behavior pattern can be various.

Five, more fit the trend of web development, this more virtual, no longer start to say this question.

VI, the technical slowdown led to the programmer lost enthusiasm for Struts2, leading to Springmvc rely on their own efforts and spring's reputation, gradually revealed its own advantages and characteristics.

Why SPRINGMVC will win the final victory. Finally, we might as well think about how the Struts2 is popular.

I used it from Struts1, and then Struts1 's problem is obvious, the open source community has a lot of MVC framework, the most prominent is the Webwork2.

WEBWORK2 explored a different solution from the traditional servlet model, which was gradually recognized by all the programmers, and became familiar with and understood. With excellent design ideas and flexible implementation, it attracts a large number of Web layer developers into its embrace.

The Apache community and Opensymphony announced that the future of the Struts project would be merged with the WEBWORK2 Project and jointly launched STRUTS2.

The main reason why Struts2 can occupy a dominant position in the development market for a considerable period of time lies in its technical leading edge. and the leading advantage of this technology, the outstanding performance is the thorough transformation to the controller:

public class Usercontroller {

Private User User

Public String execute () {

Add business logic code here

Return "Success";

}

}

From the code above, we can see that Webwork2/struts2 has two of the biggest modifications to controller: Completely eliminate the introduction of native servlet objects such as HttpServletRequest or HttpServletResponse in controller. Both the request parameter and the response data are stripped from the response method to the property variable in the controller.

These two major modifications are seen as the genius of the framework. As a result of this transformation, the entire controller class is completely decoupled from the Web container and can be easily unit tested. The controller of the servlet's bondage also gives a whole new definition to the entire programming model. From the point of view of introducing new programming elements, webwork2/struts2 is undoubtedly successful. Because the attribute variables in the forbidden controller in the traditional servlet model are reasonably exploited as part of the data in the request processing process. This transformation not only allows the expression engine to be maximized, but also makes the entire controller look more like a pojo. Therefore, this form of expression by the author's name is: Pojo implementation model. The Pojo implementation model is a revolutionary model because it can take the idea of decoupling to the fullest. From an object-oriented point of view, the Pojo model is undoubtedly a goal that all programmers pursue. This is one of the important reasons why Webwork2/struts2 has been enduring for so many years.

So, the first reason we see it is that STRUTS2 relies on technological innovation to win the favor of programmers. However, the Struts2 of technological innovation over the years seems to have taken a smaller stride. We can see that after the popularization of JDK1.5, annotation as a new Java syntax, is gradually known and applied. At this point SPRINGMVC closely followed the trend of the times, directly used for the mapping of request-response. However, Struts2 is slow to form a breakthrough on the issue of a single configuration source. Of course, this is just a simple example of technological innovation, and there are many other examples.

At least that's what it feels like. Struts is not very glory at this point, as spring's reputation and influence also objectively deepen the impression that SPIRNGMVC is a technology leader.
(ii) Summary

1, STRUTS2 is class-level interception, where a class corresponds to a request context, SPRINGMVC is a method-level intercept, a method corresponds to a request context, and the method also corresponds to a URL, So it is easy to implement restful URLs from the architecture itself, and struts2 architecture is SPRINGMVC, because a method of action in Struts2 can correspond to a URL, and its class attribute is shared by all methods. It is also impossible to identify the method by annotation or other means.

2, by the above reason, the Springmvc method is basically independent, exclusive request response data, requests the data through the parameter obtains, the processing result passes through Modelmap to the frame, the method does not share the variable, And Struts2 is more messy, although the method is also independent, but all of its action variables are shared, this will not affect the program to run, but for us to code read the program brings trouble, every time to request to create an action, One Action object corresponds to a request context.
3, because the STRUTS2 needs to be packaged for each request, the request,session and other servlet lifecycle variables are encapsulated into a map that supplies each action and ensures thread safety, so in principle, is more memory-intensive.

4, The interceptor implementation mechanism, STRUTS2 has its own interceptor mechanism, SPRINGMVC with an independent AOP approach, which results in STRUTS2 configuration file volume is larger than the SPRINGMVC.

5, The entrance to the SPRINGMVC is the servlet, and Struts2 is the filter (it is noted here that the filter and servlet are different.) It used to be that the filter is a special kind of servlet, which leads to a different mechanism, which involves the difference between a servlet and a filter.

6, SPRINGMVC integrated Ajax, easy to use, only one annotation @responsebody can be implemented, and then directly back to the response text, and STRUTS2 interceptor integrated Ajax, When handling in action, it is generally necessary to install plug-ins or write their own code into the integration, and relatively inconvenient to use.

7, SPRINGMVC verification Support JSR303, relatively more flexible processing, and Struts2 verification is more cumbersome, feel too upset.

8,Spring MVC and Spring are seamless. From the management and security of the project is also higher than the STRUTS2 (of course Struts2 can also be different directory structure and related configuration to do springmvc the same effect, but need to have a lot of XML configuration).

9, design ideas, Struts2 more in line with OOP programming ideas, SPRINGMVC more cautious, in the servlet extension. 10, SPRINGMVC development efficiency and performance is higher than Struts2.

11, SPRINGMVC can be considered already 100% 0 configured.


From: http://blog.csdn.net/chenleixing/article/details/44570681

http://blog.csdn.net/gstormspire/article/details/8239182/


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.