Struts and hibernate Review & learn about SSH combined with spring

Source: Internet
Author: User
1. MVC thoughts and advantages

MVC is not a specific design concept of the Java language, nor is it a unique idea of Web applications. It is a standard that all object-oriented programming languages should abide.
The MVC idea divides an application into three basic parts: Model, View, and Controller. These three parts work collaboratively with minimal coupling, this improves the scalability and maintainability of applications.
At first, the MVC pattern was designed for applications with different Display Requirements for the same data. The overall effect is 1.1.


In the classic MVC mode, events are handled by the controller. The controller changes the model or view based on the event type, and vice versa. Specifically, each model corresponds to a series of view lists. This relationship is usually completed by registration. That is, multiple views are registered to the same model. When the model changes, the model sends notifications to all registered views. Next, the view obtains information from the corresponding model and updates the view display.
From the perspective of the design pattern, the MVC thought is very similar to an observer pattern, but there is a slight difference with the observer pattern: in the Observer pattern, the observer and the observer can be two mutually equivalent objects, but for the MVC idea, the observer is often only a simple data body, while the observer is a simple view page.
In summary, MVC has the following features.
Multiple Views can correspond to one model. According to the MVC design pattern, a model corresponds to multiple views, which reduces the amount of code replication and code maintenance. Once the model changes, it is easy to maintain.
The data returned by the model is separated from the display logic. Model data can be used with any display technology, such as using JSP pages, Velocity templates, or directly generating Excel documents.
Applications are separated into three layers, reducing coupling between layers and providing application scalability.
The concept of the control layer is also effective because it combines different models and views to complete different requests. Therefore, the control layer includes the concept of user request permissions.
MVC is more in line with the spirit of software engineering management. Different layers perform their respective duties, and each layer of components has the same characteristics, which facilitates the generation of management program code through engineering and tool.
Compared with the early MVC idea, the MVC idea in the Web mode has some changes, because for an application, we can register the view to the model. When the model data changes, the view page is instantly notified of changes. For Web applications, even if multiple JSP pages are registered to a model, when the model changes, the model cannot actively send messages to the JSP page (because Web applications are all in Request/response mode). Only when a user requests to browse the page, the Controller is responsible for calling model data to update the JSP page.
Note that the MVC idea is similar to the observer pattern, but not identical. There are also some differences between the classic MVC idea and the MVC idea of Web applications. The main reason for the difference is that Web applications are applied in a request/response mode. For request/response applications, if the user does not send a request to the application, the view cannot actively update itself.

2. Presentation layer framework Struts

Struts is an MVC Framework Based on JSP Model2. It consists of Model, Viewer, and Controller, its main design concept is to decouple the presentation logic from the business logic through the Controller to improve the maintainability, scalability and reusability of the system.

(1) view: the view is mainly composed of JSP pages. There is no process logic, business logic, and model information, and only tag. Struts itself contains a set of tag libraries (TagLib), which is also one of the essence of Struts. Using them flexibly can simplify JSP page code and improve development efficiency.
(2) Controller: the Controller in Struts is its own ActionServlet. ActionServlet receives all requests from the client and transfers control to the appropriate Action object as defined in the configuration file (struts-config.xml.
(3) Model: Struts does not define the implementation of a specific Model layer. The Model layer is usually closely related to the business logic and has continuous requirements. At present, there are some excellent tools in the commercial field and the Open Source world to facilitate the development of the Model layer.

3. Business logic layer framework Spring

Spring is a powerful Lightweight Framework that solves many common problems in J2EE development and can replace EJB technology. Here, lightweight refers to the Spring framework itself, rather than Spring can only be used for lightweight application development. The lightness of Spring is embodied in the infrastructure of its framework and its support and Assembly capabilities for other application tools. Compared with EJB, Spring can reduce the risks between different technical layers.
The core of the Spring framework isControls flip IoC (Inversion of Control)/dependency Injection DI (Dependence Injection) Mechanism. IoC refers to the relationship between components controlled by containers (here, containers refer to a standardized runtime environment that provides specific services and technical support for components) rather than directly controlling program code in non-traditional implementations, this transfer of control from program code to external containers is called "flip" [3]. DI is a more vivid explanation of IoC, that is, the container dynamically injects dependencies (such as constructor parameters, constructor objects, or interfaces) into components during runtime. Spring uses a set-value injection (using the Setter method to implement dependencies) and a sub-injection (implementing dependencies in the constructor) mechanism to manage the set-up collaboration objects through the configuration file, create an IoC container that can construct components. In this way, you do not need to write the factory mode, Singleton mode, or other constructor methods, you can directly obtain the required business components through the container.

4. Data Persistence Layer framework Hibernate

O/R mapping technology is generated to solve the mismatch between relational databases and object-oriented programming. Hibernate is currently the most popular O/R mapping Framework. It implements an automatic ing between relational databases and Java objects, allowing programmers to perform database operations in a very simple way.
Hibernate encapsulates JDBC to shield programmers from underlying database operations, so that programmers can focus on OO program development and improve development efficiency. What programmers need to do to access the database is to compile an xml ing file for persistent objects [4].
To change the underlying database, you only need to change the Initialization Configuration File (hibernate. cfg. xml or hibernate. properties) without affecting the application.
Hibernate has its own Object-Oriented Query Language, HQL, Which is powerful and supports most mainstream databases, such as Oracle, DB2, MySQL, and Microsoft SQL Server, it is currently the most widely used O/R ing tool. Hibernate provides underlying support for rapid application development.

5. New J2EE framework integrated with SSH

The following three framework technologies are integrated to improve the traditional J2EE Web development model to form a new Lightweight J2EE architecture.




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.