The advantages of using struts+spring+hibernate

Source: Internet
Author: User
Tags requires java web

The traditional Java Web application is implemented by Jsp+servlet+javabean, which realizes the most basic MVC layering, divides the program structure into several layers, has the JSP responsible for display, the servlet responsible for the process logic control, Responsible for the JavaBean of data encapsulation. But the structure still has problems: such as JSP page need to use symbols embedded in a lot of Java code, resulting in confusion in the page structure, servlet and JavaBean responsible for a large number of jumps and calculations, coupled tightly, low program reusability and so on.

So first appeared the Struts framework, 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 responsible for data input and output display, There is also a form class that is responsible for passing the data between the action and the JSP. A set of tags provided by the Struts framework can be used in a JSP as simple as using an HTML tag, but can accomplish very complex logic. There is no need for a line of enclosing Java code from this JSP page.

But all the operational logic is in struts action will make the action class reusability and logic confusion, so usually people will be the entire Web application divided into three layers, struts is responsible for the display layer, it calls the business layer to complete the operational logic, the business layer to call the persistence layer to complete the database read and write .

Using a JDBC connection to read and write a database, our most common is to open the database connection, the use of complex SQL statements to read and write, close the connection, the data obtained needs to be converted or encapsulated after the outbound, this is a very cumbersome process.

And then there was the hibernate frame, it requires you to create a series of persistent classes. The properties of each class can be simply viewed as corresponding to the property one by one of a database table and, of course, to the various tables associated with the relational database. And then when we do it, we just have to make these persistent classes. Without having to focus on the database table. We don't have to go to a row of query database, only need * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the function of adding and checking. Our software development is really object-oriented, not chaotic. Using hibernate reduces the amount of programming by 80% compared to JDBC.

Now we have three layers, but what is the call between each layer? For example, the display layer of struts needs to invoke a business class, it needs a new business class to come out and then use the class that the business layer needs to call the persistence layer, It also requires a new persistence layer class to use. This new way of calling each other is the embodiment of the worst design in software development. To put it simply, the caller relies on the callee, which forms a strong coupling, and if I want to reuse a class somewhere else, Other classes that are dependent on this class also need to be included. The program becomes very confusing, each class relies on each other to invoke each other, and the reusability is extremely low. If a class is modified, many of the classes that depend on it will be implicated.

To do this, the spring framework appears, and its role is to completely decouple the dependencies between classes, and if a class relies on something, it's an interface. As for how to implement this interface, it doesn't matter. Just get a class that implements this interface, It is easy to inject the implementation class into the class that invokes the interface through the XML configuration file. This dependency between all classes is completely replaced by the configuration file. So the core of the spring framework is the so-called dependency injection and control reversal.

The current structure is that struts is responsible for the display layer, hibernate is responsible for the persistence layer, and spring is in charge of the middle business layer, which is the most popular Java Web application architecture in the country. In addition, because of the dependency injection used by spring and AOP (aspect-oriented programming), So its internal model is so good that spring itself implements an MVC framework using dependency injection, called Spring MVC, and Spring integrates hibernate to handle things well. Make things management from the hibernate of the persistence layer to the business layer, the use of more convenient and powerful.

The struts framework was started in 2000 and has been developed for 5 years, and the technology is quite mature, At present, the struts framework in global Java development is a well-deserved king in the display layer technology. It has a large user base and a good development team. This is the basic requirements of most of the domestic Java software companies for new employees, so I highly recommend the mastery of struts technology, which will be good for your employment. .

The term Java seems destined to be closely linked with open source, in the Java world, there is a large number of open source technology every day, because it is open source, the problems and deficiencies in technology will soon be discovered, open source software providers will quickly modify or expand these technologies, so the version is updated quickly, A new version will come out in a few weeks or a few days.

Choose Java, you have to continue to learn, you need to constantly focus on the latest technology, understand them, see if it suits your needs, and then learn to use them. As long as you do not pay attention and study for a while, then you are behind others, style= "font-size:14px", can only do as coder, cannot become the main force, even was swept out.

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.