1.MVC Design Ideas
The concept of MVC program design is a popular model of web development, in whichM (model) is modeled as JavaBean, which is used to encapsulate and store data; V (view) is a view, which is a JSP, which is used to display content; C (Controller) The servlet, which is used to process business logic . The general process is this: write a JSP page to obtain information (such as the login page to get the user login, password), and encapsulate the information into JavaBean, submitted to the server driven by Web container to encapsulate the data as request requests, to the servlet processing. The servlet obtains the user information from the request into the database query, returns the corresponding result (login success or failure), and then encapsulates the result into a response response to the client browser, which is displayed according to the response header and other information.
The MVC design idea separates the data encapsulation, the display and the business processing, the JavaBean, the JSP and the servlet all do their own best thing, the modularization makes the whole process clearer, conforms to the Java low-coupling idea, improves the code flexibility, is easy to expand and maintains. Specific division of labor such as:
2.WEB three-tier architecture
It can be seen from the data access layer that JavaBean both the data content and the data content, which violates the principle of single responsibility. We hope that JavaBean is simply used to encapsulate the data and others to do it, so in web development, the data access layer is further refined, JavaBean to encapsulate the data, and the data is persisted in the database (also can be XML files), through the DAO (data Access object) data Access objects to query the database (or parse XML files, etc.). Sometimes the view layer is not necessarily JSP-only, and some content needs to be displayed through servlet technology, such as a verification code for the login page. When the business logic is too large, the business logic layer will appear particularly bloated, not conducive to the expansion and maintenance, when the business functions can be abstracted into an interface, the specific functions of the subclass implementation. So the question comes, how do you know which class to deal with which business logic? The solution is to define a core servlet that receives all client requests and passes the request to the corresponding business processing subclass to handle it. Here you can see the implementation principle of Struts2, which is not mentioned here. In this way, the business logic layer is divided into two parts: the servlet for display and the servlet that distributes the business. Such as:
3 . Real Case
However, in real development, the above is not the ultimate solution. Take a practical case, develop a simple business-to-consumer electronic trading platform System (features include: User login, registration, email verification, view products, add goods, shopping cart, order, online payment, etc.), the package structure is as follows:
~ ~ to Be Continued ~ ~
Above are personal views, if in doubt, Welcome to Exchange ~ ~
Thinking about the Web three-tier architecture