Understanding of the Java EE Framework (struts&hibernate&spring)

Source: Internet
Author: User

Ssh:
Struts (presentation layer) +spring (business layer) +hibernate (persistence layer)
Struts:
Struts is a presentation-layer framework that mainly functions as interface display, receiving requests, and distributing requests.
In the MVC framework, struts belongs to the VC level, responsible for the interface performance, responsible for the distribution of MVC relationship. (View: jsp,http,form,tag,resourse; controller:actionservlet,struts-config.xml,action)
Hibernate:
Hibernate is a persistent layer framework that is only responsible for operations with relational databases.
Spring:
Spring is a business-layer framework that is an integrated framework that is well-bonded to the presentation and persistence layers.

We know that traditional Java Web applications are implemented using Jsp+servlet+javabean, which implements the most basic MVC layering, which divides the program structure into several layers, the JSP that is responsible for the foreground display, The servlet responsible for the process logic control and the JavaBean responsible for the data encapsulation. However, this structure still has problems: such as JSP pages need to use symbols embedded in a lot of Java code, resulting in a confusing page structure, servlet and JavaBean responsible for a large number of jump and computation work, coupled tightly, low program reusability and so on.

Struts

In order to solve these problems, the struts framework has emerged, it is a perfect MVC implementation, it has a central control class (a Servlet), for different business, we need an action class responsible for page jump and background logic operation, One or several JSP pages are responsible for the input and output display of the data, and a form class is responsible for passing data between the action and the JSP. A set of tags provided by the Struts framework can be used in JSPs, as simple as HTML tags, but it can be done with very complex logic. There is no need for a line of Java code to appear in this JSP page. But all the arithmetic logic put in the struts action will make the action class reusability low and logical confusion, so usually people will divide the entire Web application into three layers, struts is responsible for the display layer, it calls the business layer to complete the operational logic, the business layer calls the persistence layer to complete the database read and write. Using the JDBC connection to read and write the database, our most common is to open the database connection, the use of complex SQL statements to read and write, close the connection, the obtained data needs to be transformed or encapsulated after the rumor, this is a very cumbersome process.

Hibernate

There is a hibernate framework, which requires you to create a series of persistent classes, each class of properties can be easily seen as a database table of the properties of one by one corresponding, of course, you can also implement the relational database of the various forms of the corresponding correlation. When we need to do this, we don't have to focus on database tables. We do not have to go to a row of query database, only need to persist the class to complete the function of the increase and deletion check. Make our software development truly object-oriented, rather than code that is confusing. My feeling is that using hibernate reduces the programming amount by 80% compared to the JDBC approach. Now we have three layers, but what is the call between each layer? For example, the struts of the display layer need to invoke a business class, it needs new business class to come out, then use it, the business layer needs to invoke the class of the persistence layer, and it needs to use the new persistence layer class. Invoking each other in this new way is the embodiment of the worst design in software development. Simply put, it is the caller who relies on the callee, which forms a strong coupling, and if I want to reuse a class elsewhere, the other classes that the class relies on are also included. The program becomes chaotic, with each class relying on each other to invoke each other, with a very low degree of reusability. If a class has been modified, many of the classes that depend on it will be implicated. To do this, the spring framework appears.

Spring

Spring's role is to fully decouple the dependencies between classes, and if a class depends on anything, it is an interface. As for how to implement this interface, this is not important. As soon as you get a class that implements this interface, you can easily inject the implementation class into the class that invokes the interface through an XML configuration file. This dependency between all classes is completely superseded by the configuration file. So the core of the spring framework is the so-called dependency injection and control inversion. Now the structure is, struts is responsible for the display layer, hibernate is responsible for the persistence layer, spring is responsible for the middle business layer, this structure is the most popular Java Web application architecture in the country now. In addition, because of the dependency injection and AOP (aspect-oriented programming) used by spring, it
This internal model is so good that spring itself implements an MVC framework that uses a dependency injection, called Spring MVC, and in order to handle things well, spring integrates hibernate, Enables the management of things from Hibernate's persistence layer to the business layer, which is more convenient and powerful to use. The struts framework was started in 2000 and has been developed for more than 5 years, and the technology is quite mature, and the struts framework of the global Java development is a well-deserved king in the display layer technology. It has a large number of user groups and a good development team. This is also the majority of the domestic Java software companies to new employees basic requirements. Other Java the term seems destined to be closely linked with open source, in the Java world, there are a lot of open-source technology every day, because it is open sources, the problems and shortcomings in the technology will soon be discovered, open source software providers will quickly modify or extend these technologies, so the version is updated quickly, A new version comes out in a few weeks or days. When we choose Java in the technology line, we choose that you must continue to learn, always focus on the latest technologies, know them, see if they are right for you, and then learn to use them.

Understanding of the Java EE Framework (struts&hibernate&spring)

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.