Understand Web applications in a macro perspective (Java Edition)

Source: Internet
Author: User

In the middle and late 1990s s, with the rise of the Internet, people strongly hope that the use of applications can be as pleasant as browsing web pages. The traditional C/S structure application requires every user
If a client software is installed on your computer, there is no way to access the application on the server. Therefore, the awkwardness of the C/S structure lies with the simple demand of the masses for daily growth,
As a result, it is unable to adapt to the experience of this era and gradually withdraw from the historical stage of program development.
The application and the C/S structure are different, instead of B.
/S. Application Development has ushered in the web era. Java, which is the Web application's leading Java program, first appeared in the form of Applet (small application.
The application form at that time was a small application released on the server. When accessed by a browser, it was downloaded to the client's computer for running. This causes security risks. For example, if the Applet
Contains sensitive information such as the URL, user name, and password of the database. When the applet is downloaded to the local computer, you can find a decompilation tool, it is easy to obtain the original Applet
Code, even more compliant with coding specifications than programs written by some spam programmers. At this time, as long as you are not a fool, you can understand the connection information of the database. This is equivalent to telling the thief: "I just got 0.5 million silver at home.
There are no people in the house, no locks in the door, and I have no habit of raising a dog !". If a thief does not visit your home, it is a matter of character.
Carefully analyze the security of the applet.
The reason is that the applet runs on the client. Based on security considerations, we hope that Java programs can move from the client to the server. The program runs on the server and is not downloaded to the client computer.
. The first technology that emerged at this time is servlet, which meets the requirements of Java security. However, the following problem is that the servlet displays all
Web code must be completed on the server, that is, Servlet not only needs to schedule the server process, but also is responsible for page implementation, and the original concise HTML once in the Servlet
It becomes extremely cumbersome, which brings new troubles to the development process, seriously affects the development efficiency, and thus affects the extensive promotion and use of servlet.
Soon after, Sun finally recognized
I realized that I was a little too CNN, so for the purpose of simplifying servlet applications, I introduced a new generation of Web application technical specifications, which is the JSP specification. JSP is embedded in HTML
The Java code method solves the problem that Servlet's implementation of page display is too complicated, and makes Web Application Development enter a brand new era. However, the unfortunate Sun Company fell into another trap
New problems are introduced. We need to think carefully about the "logical problem" in the software development process ".
In my opinion, a Web application should contain three Logics,
This is the display logic-display of pages; control logic-scheduling of processes, that is, the calling class for data processing, data operations, and the calling page, displays the data generated by the operation.
Business logic-This refers to complicated and complicated business operations and data processing.
Through the analysis of JSP, we found that the HTML part of JSP should be responsible for the content displayed on the page, which is a display
The scope of logic, while java scripts are mainly responsible for data operations and data processing, should belong to the scope of business logic. JSP does not properly divide the two logics, resulting in the display logic
It is intertwined with the business logic (this is the so-called high Coupling Degree), causing great inconvenience to the testing process and later maintenance of the program. As a result, sun's Great programmers started to use
Those who complained and smothered smog had a profound and delicate reflection.
One day, when a group of programmers relaxed their nerves under the apple tree, suddenly there was a strong wind, and the trees were like hail.
The new application method was born, and the brilliant journey of Java in Web Application Development was truly started, and still laugh till today
The world is unbeaten! So what do they think?
They found that for three logics, JSP's strength lies in page display, which can be used to process the display logic; Servlet's strength is
Process Scheduling can extract a large number of statements in JSP for process scheduling and hand them over to the servlet for processing. In this way, the control logic problem is well solved. What should we do with the business logic?
Where? In addition to data encapsulation, JavaBean can also be used. Why not use the JavaBean method to process the business logic? There is no reason! Use it. Therefore, the business logic
To solve the problem, we also found a suitable solution (later, with the improvement of programming ideas and art, the relationship between JavaBean and common Java classes is becoming increasingly blurred, and people prefer to use
Any standard Java class is used to process business logic and give it a name to better advocate this idea. This is pojo-common Java class ). Therefore, the three logics are implemented by different operators.
Since then, the application of three logics in different complex business systems has produced two models: model1 (JSP + JavaBean) and
Model2 (JSP + servlet + JavaBean ). Model1 is suitable for small-scale systems, such as websites. For complex enterprise-level applications (such as financial systems,
(Social Security system, etc.), Sun recommends model2.
After the appearance of model2, people found that in actual application, JSP focuses on page display.
Servlet focuses on process control, while JavaBean focuses on business processing. This is very similar to the traditional MVC. The traditional MVC includes three aspects: content, model, view,
Controller. Model: focus on data processing; view: focus on data display and report processing; Controller: Coordinates models and views. Therefore, people started to think that model2 is based on MVC. Personal Opinion
If you only develop your website, you can use model1 for convenience. Why? Model2 is somewhat complicated.
With the development of modern society, the complexity of business rules has exceeded people's imagination. However, the customers who are jealous do not care about this. The total time they give us is fixed. Software companies have always been in a weak position in the process of getting along with customers, and they have no right to speak. The reason is very simple. Because the company wants to make profits, we need to make money for the customers!
Customer
If the user limits the time, the project cycle is also limited. For a complex system, when the total amount is certain, we are always looking for the optimal ratio of technical time to business design time. Fixed project cycle
The technical time is inversely proportional to the business design time. There is a long shift between the two. If it takes a long time for technical processing, the business design time will inevitably be shortened. Similarly, if the time needed for business processing needs to increase
You must shorten the technical processing time. In the selection process of the two, we have to shorten the technical time. The reason is very simple. The business rules are getting more and more troublesome. The customer doesn't tell you the truth. While
Model2, although well solved the division of three logics, can be applied to enterprise application development, but too cumbersome, implementation method is too rough. Many basic services are not provided for us. Ratio
For example, request Distribution and data acquisition during the request process. Therefore, people want to replace model2 with a new method or simplify the application of model2. Based on this, a large number of model2-based
Web frameworks have sprung up. The best of them are struts1 and webwork. Later, the two were integrated to form struts2. Because they are both
Because model2 and model2 are based on MVC, people think that they are all based on MVC ideas.
Struts1 is the first mature MVC-based
Web framework. His appearance greatly simplifies the application of model2. We will learn about it in the subsequent sections and discover its conciseness and beauty. Struts1 simplifies model2
But it only solves the web layer problem of enterprise-level application systems. So which layers are there for enterprise application systems? Why? How can these layers be used to better solve them?
MVC
It has been around for 40 years. In the face of complicated modern business rules, he is old and uses it to solve today's problems, it's like deducting Qin Shihuang from the ground and giving him a remote
The Controller said, "Dude, shut down the TV !". It is estimated that this buddy must have been furious and replied to you: "drag it out, let it go !". Now that MVC is old, the answer is:
System Architecture!
Next, let's take a look at the stratified thinking throughout the subsequent chapters.
A good application system is generally based on a layered architecture. The hierarchical architecture is roughly shown in:

The display layer corresponds to the MVC view (v), and the control layer corresponds to the MVC controller (c). In subsequent chapters, we merge them together, collectively referred to as the web layer (also known as the presentation layer in some books ). Struts solves the technical implementation of the web layer here. What are the other layers and what are the technologies used for implementation?
With
With the increasing complexity of business rules, data processing is becoming more and more complex, and the birth of database technology solves this problem well. It can be said that today's application development is basically inseparable from databases
Operation, processing, and finally data must be stored in the database for future queries or further data analysis and processing. In this way, the final purpose of the program design will be converted to the retrieval of the database.
Analysis and update. That is, the data in the memory must be stored in a database for long-term storage. This is the so-called data persistence. The data persistence layer is a dedicated system logic for solving persistence.
Layer. Currently, Hibernate is the most widely used data persistence standard. In addition, the ejb3 technology that has emerged in the future belongs to this category, and its future is also limitless.
When
After the emergence of the persistent layer technology, what is its relationship with the original model, its position inside the model, and how to apply the persistence technology, these are not clearly defined in the original MVC. This is also
One reason why MVC is outdated is that its model concept is too rough and too general. The hierarchical architecture clearly defines this. Persistence Layer, only responsible for solving data persistence (adding and deleting data persistence objects)
For better application of the persistent layer, the business logic layer is introduced. This layer is generally a common Java class (pojo). It is responsible for combining multiple persistence components to complete
Miscellaneous commercial processing (such as interest calculation, account carry-over, and bank transfer ).
In a software system, there are often some classes that provide basic services, such as guid generation, MD5 encryption, and
Handling, email sending, and so on. We find that they provide basic services for specific business processing, but they are not dedicated to any specific business logic. To this end, the Hierarchical Architecture
It is abstracted separately to form the system service layer. At this layer, we also use common Java classes (pojo) for processing.
Based on the above analysis, we can see that the hierarchical system is
Generally, there are four macro logical layers: web layer, business logic layer, persistence layer, and system service layer. At the same time, the layered architecture also defines their mandatory scheduling relationships: "The same layer and phase
The adjacent layers can access each other and do not allow layer-4 access ". For example, the control layer cannot directly access the persistent layer across the business logic layer.
After the emergence of the layered system idea, each component in the software development system has a suitable position. We can stride forward with peace of mind. Is that true? Practice is the only criterion for testing everything. The real factors determine the life cycle of all technologies and thinking!
In the practical application process, new problems have emerged.
In
While completing complex functions, we have been pursuing reuse of existing functions (components. The best way to reuse is to generate new functional points through the combination of existing components. This inevitably involves Components
The call method between them. Traditional component calling methods are called and combined by the application itself to manage components, resulting in high coupling between components, independent testing of components and post-Maintenance of the entire system
It brings a lot of trouble, so that the improvement of software quality is just like a mirror, and it cannot be achieved technically. At the same time, in the application of Object-oriented Thinking, Great programmers found that object-oriented thinking only solves the problem.
There is a vertical consistency between things, and there is no good solution for the horizontal public features that run through all functional points of the system, such as system logs, security support, and transaction management. To solve the above problems
A new framework is spring. In spring, di (dependency injection) is used to solve the scheduling problem between components. At the same time, introduce AOP (Surface
It solves the problem of common functions. This has brought a profound revolution that touched the soul of software development. The software industry has ushered in the real spring.
In this book's knowledge system, for the implementation of layered architecture, the web layer will adopt struts1.x, And the persistence layer will adopt hibernate. Spring2.x is used for macro scheduling and transaction processing among components in the entire architecture. This is the popular SSH integrated architecture design.
The above discussions on data persistence, layered architecture, and dependency injection are just a simple introduction, the goal is to give readers a rough understanding of the hierarchical architecture and its SSH implementation. In the subsequent chapters, this book will elaborate in detail. Don't worry. You can't eat hot tofu. Stick to it and everything will be fine. After all, there is hope to live!
Things
Things are going through a process from scratch, from weak to strong, and influenced by practical factors, our understanding is always limited. With the deepening of practice, people's programming ideas and programming technologies are constantly maturing
And development, new application technologies and methods will gradually emerge. From this perspective, there are countless new ideas and technologies waiting for us to discover and implement. The fun of programmers is also here: Yes
Constantly come into contact with novel worlds and ideas. The chest contains Guangyu, and the weather is huge!
Finally, let's interpret Mr. Lin's passage as the end of this article:
Let us hold high the great banners of Java and software engineering ideas, closely unite around the software giant with sun as the core, following Mr. Bill Gates's Financial Path, vomiting blood programming day and night, it comprehensively pushed the great undertaking of building software industry with Chinese characteristics to the 21st century. Build a Harmonious Society and enjoy a prosperous life!

Related Article

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.