The difference between SpringMVC, Struts2

A, Spring and SpringMVC difference:  

spring is an open source framework to solve the enterprise application development, the following functions:  

Function: instead of using the basic JavaBean EJB, and provides more enterprise applications  

Range: any Java application Spring is a lightweight inversion of control (IoC) and section (AOP) facing the container frame.

   1, lightweight - from the cost in terms of both size and Spring are lightweight. Complete Spring Framework can be published only 1MB in size and more of a JAR file. Spring and processing overhead required is negligible. Further, Spring non-invasive: Typically, Spring application object is not dependent on a particular type of Spring.  

  2, controlled by means of a reverse --Spring called Inversion of Control (IoC) technology for the loose coupling. When you apply IoC, an object dependent on other objects will be passed in through a passive, rather than the object itself to create or find the dependent objects. You can think of IoC and JNDI opposite - look for a dependency from the container is not an object, but the object is initialized when the container objects ranging request will depend on the initiative passed to it.   

3, provides for extensive support section --Spring Oriented Programming, allowing for the development of cohesion by application of separating business logic and system-level services (such as auditing (Auditing) and transaction (transaction) management). Application object is only realized they should do - to complete the business logic - nothing more. They are not responsible for (or even awareness) of other system-level concerns, such as logging or transaction support.   

4, container --Spring application object contains and manages the configuration and life cycle, in the sense that it is a container, you can configure how each of your bean is created - based on a configurable prototype (prototype), you the bean can create a single instance or every time a new instance is generated when needed - and how they are interrelated. However, Spring should not be confused with the traditional heavyweight EJB container, they are often bulky and cumbersome, difficult to use.   

5, the frame may be --Spring simple component configuration, combined into complex applications. In Spring, application objects are declaratively combined, typically in an XML file. Spring also provides a lot of basic functionality (transaction management, persistence framework integration, etc.), the application logic developed left you. All of these features Spring enables you to write cleaner, more manageable, and easier to test code. They also provide the foundation support for the Spring various modules. Two core and IOC Spring AOP can be used to separate any application, including integration with MVC frameworks such as Struts and Hibernate and other ORM framework, many companies is to use so-called lightweight development Spring + Struts (2) + Hibernate.    

Spring MVC is an MVC framework, personally I feel that Spring MVC annotation style of development more convenient than Struts2, instead of directly above Struts (Struts course of MVC as a very mature, still feel a little stronger than Spring functionality, but Spring MVC has enough to use). Of course, the efficiency is higher than spring mvc struts, because the value of the stack affect the efficiency of the struts.    

similar to a spring mvc struts MVC framework open, in fact, belong to the spring, spring mvc need to have a spring frame as a support package to run up.

   Two, Spring and Struts2 difference:     

Struts2 is an interceptor stack is a series of interceptors. A user request processing, the use of OGNL, verification forms are the default function in the interceptors.     

spring interceptors, mainly in terms of transaction management AOP, there are some log display such error or anomaly is a log by configuring the spring interceptors to achieve.  

Three, StringMVC with Struts2 difference:     

   1, Struts2 intercept a class level, a class corresponding to a request context, SpringMVC levels intercept method, a method corresponding to a request context, while at the same time any connection with a method corresponding to url, so that from the architecture itself can easily achieve restful SpringMVC url, and struts2 framework to be laborious to implement, because a method Struts2 in Action may correspond to a url, and it was all methods share class attribute, it will not be able to identify their respective method with annotations or the other way.

    2, is substantially independent of the method SpringMVC, exclusive request response data, parameter data acquisition request, the processing result returned by ModelMap to frame, the method does not share variables, and to engage Struts2 chaotic, although the method of between is independent, but all its Action variables are shared, this will not affect the program runs, gave trouble when we read the coding procedure, each to a request to create a Action, an Action object corresponds to a request context .

    3, Struts2 request is required for each package, the variable request, session servlet like a life cycle of a package into the Map, supplying each Action use, and to ensure thread safety, so in principle, it is more memory-intensive.

    4, interceptors to achieve the mechanism, Struts2 interceptor has its own mechanism, SpringMVC use of AOP is an independent manner, which leads to the configuration file is larger than the amount of Struts2 SpringMVC.

    5, SpringMVC entrance is servlet, and is the Struts2 filter (here to point out, filter and servlet is different. Previously thought servlet filter is a special), which led to two different mechanisms, here involves the servlet and the difference of the filter.

    6, SpringMVC integrated Ajax, very easy to use, just a comment @ResponseBody can be achieved, then returns the response directly to the text, while the Struts2 interceptor integrates Ajax, you must install the plug-in handling general in the Action or write your own codes integrated into, using them is relatively inconvenient.

    7, SpringMVC validation support JSR303, treatment is relatively more flexible, but more complicated Struts2 validation, feeling too upset.

    8, SpringMVC Spring and is seamless. Also from the management and security of this project Struts2 higher than that (of course SpringMVC Struts2 also can do the same effect by a different directory structure and configuration, but many places require xml configuration).

    9, design thinking, Struts2 more in line with the OOP programming ideas, SpringMVC is more cautious, spread over servlet.

    10, SpringMVC development efficiency and performance than Struts2.

    11, SpringMVC can be considered to have 100% zero-configuration

1, the analysis from the perspective of safety spring mvc and the difference between the struts2:

spring mvc:controller

1.spring mvc default controller is a single-instance (via annotations @Scope ( "prototype") becomes a multi-instance); 
non-thread-safe single instance 2. Do not define the member variables (instance variables) in the controller; 
3. Single Instance , the web began when instantiating Controller startup container, the most important matter global instance, each access this example response; 
4. multiple instances, each visit, the majority & basic (example reuse found occasionally) will produce a new instance of the corresponding response; 
5. single-instance, concurrent requests, when synchronized synchronous access method, blocking Effect (method instance locks synchronized) with each other; 
6. multi-instance, concurrent requests, access time synchronized synchronization method does not affect each other ( examples lock synchronized method);

 

struts2:action

1.struts2 provide an action instance for each thread, the problem does not occur when multiple threads access. When action instance object spring struts2 of management, scope must be configured to prototype or session; problem can occur if the singleton is configured for multithreaded access, for example actionMessage, fieldError and other information will be cumulative, multi-user access to some user access is another user data. 
2.scope = "prototype" is a request instance for each action (struts2 and mechanism is the same). 
scope = "session" is to provide an action instance for each session. 
3. commonly used prototype, providing a container that is let spring action instance for each request, the server side benefit is that users do not have to maintain state information, otherwise the session state information must be stored on the server side, server-side user for a long time occupy too much memory. When using the prototype, the client must themselves maintain user state, when the server each time you visit will be submitted to the appropriate state information to the server. 
For example, when scope = "prototype", page typically <input name = "id" type = "hidden" value = "$ {id}" /> is used to store user id information, access to the submitted action in the action for the server-side function uses. And when using a scope = "session", page without the use of hidden objects hidden id information, as long as the service end users who obtain the id, action id attribute this information is saved.

2, analysis of the difference between springmvc and struts2 as a whole 

1, springmvc based development, struts2 class-based development.
springmvc to map the url and controller method. After the mapping is successful springmvc generate a Handler object, the object includes only one method. Method has finished executing, shape parameters, according destroyed.
All methods of struts2 action class member variables are used in the class action, once the process becomes a lot of time, we will not know so many members of the class action is a variable that method to use. Very confusing.
However, all parameters are defined as springmvc method parameter, such parameters will be the method used to form the injection parameters of the corresponding method, so that the controller springmvc develop similar service development.
2, springmvc a single embodiment may be developed and proposed that a single embodiment developed by the class member variable struts2 receive parameters, can not use a single embodiment, many cases of use only.
3, after the actual test, struts2 slow that use struts tag, if using struts recommended jstl.
  Finally, we can not actually define springmvc and struts in the end who is good or bad, can only say that early struts due to the use of more, it is more and more loopholes. If you use the recommended struts, on the use of the latest package, because in the past there may be a loophole. But springmv now almost no vulnerability, which is why springmvc recent years began to pop up, then there is a springmvc is based on the method developed, closer to service development.


springmvc summarized
springmvc frame:
the DispatcherServlet front controller: receiving a request, for Response
the HandlerMapping mapping processor: Find Handler The url. (Via xml configuration, annotation mode)
HandlerAdapter Processor Adapter: Handler to perform in accordance with certain rules, it is necessary to prepare the preparation in accordance with the requirements of HandlerAdapter Handler.
Handler processor (back-end): the need for programmers to write, annotate common development approach.
After the execution result is Handler Processor ModelAndView, Handler returns the specific value type developing method comprising: ModelAndView, String (logical view name), void (request and response by adding the parameter Handler in a manner similar to the original servlet development, Note: You can results response by specifying the type of response achieved json data output)
view view resolver resolver: generating a logical view of the real view name (used in springmvc view object represented)
view view: JSP pages, only the data show, no business logic.

 

springmvc and struts2 differences:
springmvc oriented development method (developing an interface closer service mode), struts2 class oriented development.

springmvc singleton can develop, struts2 can only be a multi-case development.

Guess you like

Origin www.cnblogs.com/wyf-love-dch/p/11546604.html