Analysis of Java Web Framework Technology

One, the concept of Java Web framework technology

  The so-called Java framework, simply understood as a reusable design component, specifies the architecture of the application, clarifies the entire design, the dependencies between the collaborative components, the assignment of responsibilities and the control process, and is represented as a set of abstract classes and The method of collaboration between its instances, which provides a context relationship for component reuse. Struts, Hibernate, and Spring are commonly used frameworks in Java development, and they provide the most suitable solutions for different application scenarios.

Second, the development process of Java Web framework technology

  Traditional Java Web applications are implemented using JSP+Servlet+Javabean. This model implements the most basic MVC layering, and the program structure is divided into several layers. There are JSPs responsible for the front-end display and the logic control of the process. Servlet and Javabean responsible for data encapsulation. However, there are still problems with this structure: for example, a lot of Java code needs to be embedded with symbols in the JSP page, causing confusion in the page structure, Servlet and Javabean are responsible for a lot of jump and calculation work, tight coupling, low program reuse, and so on.

  In order to solve these problems, the Struts framework appeared. It is a perfect MVC implementation. It has a central control class (a Servlet). For different businesses, an Action class is required to be responsible for page jumps and background logic operations, one or more A JSP page is responsible for data input and output display, and a Form class is responsible for transferring data between Action and JSP. A set of tags provided by the Struts framework can be used in JSP, as simple as using HTML tags, but very complex logic can be completed. From then on, there is no need to surround a line of Java code in the JSP page.

  But putting all the operation logic in the Struts Action will make the Action class reusability low and logic 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 operation logic , The business layer then calls the persistence layer to complete the reading and writing of the database.

  Use JDBC connection to read and write the database, the most common of us is to open the database connection, use complex SQL statements to read and write, and close the connection. The obtained data needs to be converted or encapsulated before being transmitted. This is a very cumbersome process.

  At this time, the Hibernate framework appeared. It requires you to create a series of persistent classes. The properties of each class can be simply regarded as a one-to-one correspondence with the properties of a database table. Of course, various tables of relational databases can also be realized. Correspondence of file association. When we need related operations, we no longer need to pay attention to database tables. We don't need to query the database row by row, only the persistent class can complete the addition, deletion, modification, and query function. Make our software development truly object-oriented, rather than chaotic code oriented. My feeling is that using Hibernate reduces the amount of programming by 80% compared to JDBC.

  Now we have three layers, but what are the calls between each layer? For example, if the Struts of the display layer needs to call a business class, it needs to create a new business class and then use it; the business layer needs to call the persistence layer class, Also need to use a new persistence layer class. Calling each other through this new method is the embodiment of the worst design in software development. Simply put, the caller depends on the callee, and a strong coupling is formed between them. If I want to reuse a class in other places, other classes that this class depends on also need to be included. The program becomes very messy, each class depends on each other to call each other, and the degree of reuse is extremely low. If a class is modified, many classes that depend on it will be implicated. For this reason, the Spring framework appeared. The role of Spring is to completely decouple the dependencies between classes. If a class depends on anything, it is an interface. As for how to implement this interface, it doesn't matter anymore. As long as you get a class that implements this interface, you can easily inject the implementation class into the class that calls the interface through the xml configuration file. This dependency between all classes is completely replaced by configuration files. So the core of the Spring framework is the so-called dependency injection and inversion of control.

  The current structure is that Struts is responsible for the display layer, Hibernate is responsible for the persistence layer, and Spring is responsible for the middle business layer. This structure is currently the most popular Java Web application architecture in China. In addition, due to the dependency injection and AOP (Aspect Oriented Programming) used by Spring, its internal model is so excellent that Spring itself has implemented an MVC framework that uses dependency injection, called Spring MVC, which is also very good To deal with things, Spring integrates Hibernate, which promotes the management of things from the persistence layer of Hibernate to the business layer, making it more convenient and powerful to use.

3. Current popular framework technology and development trends

  In addition to the Struts, Hibernate and Spring mentioned above, the more popular one is the Spring MVC framework. Spring MVC is a follow-up product of SpringFrameWork and has been integrated into Spring Web Flow. The Spring framework provides a full-featured MVC module for building Web applications. Using Spring pluggable MVC architecture, when using Spring for WEB development, you can choose to use Spring's Spring MVC framework or integrate other MVC development frameworks, such as Struts1, Struts2, etc. It is a typical textbook-style MVC framework, unlike struts, which are all variants or frameworks that are not completely based on the MVC system. Spring is the best for beginners or those who want to know MVC. Its implementation is a textbook. Type, it is a pure servlet system like tapestry, which is also its advantage compared to tapestry struts. And the framework itself has code, which seems easy to understand.

  The emerging frameworks include Jersey, springboot, play, Vue.js, jfinal, etc. Jersey RESTful framework is an open source RESTful framework that implements JAX-RS (JSR 311 & JSR 339) specifications. It extends the JAX-RS reference implementation, provides more features and tools, and can further simplify RESTful service and client development. Although relatively young, it is already a product-level RESTful service and client framework. Similar to Struts, it can also be integrated with hibernate and spring frameworks. As the integration of Struts2+hibernate+spring has a high market share, few people pay attention to Jersey. So there are very few introductions about Jersey on the Internet. But it is indeed a very good framework. For on-demand services, for GET, DELETE requests, you even only need to give a URI to complete the operation. 

  The springboot framework is called a one-stack solution. Relatively lightweight, it is also the current trend of microservices; springboot itself is built on top of spring. Needless to say, various ideas and features need not be said. The cumbersome configuration of spring is removed, the original spring development process is simplified, and various Practical features such as metric, actuctor, etc.; the most important thing is that springboot comes with the entire springcloud ecosystem. The two frameworks are no problem for you to solve large, medium and small projects.

  Play is more biased towards scala, with its own light weight and high performance. With the gradual optimization of ease of use and scalability, it becomes better and better.

  JFinal is an extremely fast web development framework based on the Java language. Its core design goals are rapid development, less code, simple learning, powerful, lightweight, easy to extend, and Restful. While having all the advantages of the Java language, it also has the development efficiency of dynamic languages ​​such as ruby ​​and python.

Guess you like

Origin blog.csdn.net/a159357445566/article/details/109298825