Web Architecture and MVC architecture

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

About b/S and C/s:

The management software uses B/s architecture, and the game is based on the graphics card to achieve a brilliant effect, so use C/s architecture. b/s structure is easy to maintain, upgrade and modify the program, so the future B/s still has a lot of room for development. But note does not mean that there is a browser must be B/s structure, such as the small game on the web is the C/s architecture, but it is playing while downloading, b/s architecture and C/s architecture The most essential difference is that b/s is a light client Heavy server architecture, it put all the logic, page footage on the server, Everything on the browser is downloaded from the server, so that is not a browser is b/s architecture, it should be said to meet the light client Heavy server This mode is b/s architecture, again such as small program although there is no browser, but it is a B/s architecture.

Web schema:

The Web schema can be understood to have three kinds, one is only JSP page, that is, all the logic, Business processing and page code are on the JSP, in doing some simple and unimportant program can be used in this way, fast, but not conducive to modification and maintenance, the second is a JSP and Servlet, the two division of labor, JSP is responsible for the page code, the servlet responsible for logic, data validation and database operations, the third has JSP, servlet and Java classes, JSP responsible for page code, servlet responsible for data validation, Java class is responsible for logical and database operations, this level of division of labor is the most distinct, Easy to maintain, modify and upgrade. Because Java classes do not involve specific business, so long as the same or similar functions can be copied this Java code, this can speed up the efficiency of development. In addition, the servlet needs to be run on the Web server, if one day said no longer use JSP, then Java Class Code can also be used, only need to replace the JSP and servlet parts of the code, but if the code is written on the JSP or JSP and servlet, It can be difficult to modify, even if the code is useless, and it starts from scratch. For example, we use JSP, Servlet and Java program, if it is required to interface with the small program, because the applet does not need a page, only need to return to it a JSON data, then our JSP and servlet is not available, but the Java class can also be preserved, We just need to rewrite the data inside the servlet to return the JSON data.

MVC Architecture:

Introduction: M refers to the model, v refers to the view, C refers to the Controller, note that the MVC architecture is not a three-tier architecture, if not to classify, it is at most three layers of the structure of the layer. MVC architecture is not a B/s architecture in order to use, it first appeared in the C/S architecture, MVC architecture is just a solution to the code of the architecture, who can use it, whether it is Java or C #, whether it is the B/s architecture or the C/s architecture ... Of course after doing development we can not write this framework ourselves, there is a special framework to implement this architecture, such as STRUSTS,SPRINGMVC.

Principle:

MVC is used to solve Fanluan's mesh code jump problem, as shown, if we have a lot of pages between the jump, it will be as very Fanluan:

So if there is a page with code changes, then the contact with the page is likely to need to change, we also have to find out to modify, very troublesome, very difficult, and MVC can help us solve this problem, as shown, MVC has a transit point, all the pages are connected to this broker, Then to jump to which page, directly in the transfer station to find it, so that the convenience of a lot of the station here is the controller mentioned above.

    1. Two types of models in MVC:

3.1 Model 1: View (v) >>> Controller (C) >>> model (M) >>> view (v)

As shown in the following:

The view sends the request to the Controller, the controller finds the model, and the model responds to the related page to the view. such as a login page, the first to send a request to the controller, the controller can be done by the servlet, or filter to do, as long as the request can be received, the controller to find the corresponding model, that is, Java class, of course, in this process Java class may perform a series of operations connected to the database, The Java class then returns the corresponding page-to-view for success or failure after it finishes running.

3.2 Model 2: View (v) >>> Controller (c) >>> model (M) >>> Controller (c) >>> view (v)

As shown in the following:

The view sends the request to the Controller, the controller finds the model, the model connects to the controller, tells it the result of the run, and the Controller responds to the relevant page to the view. Or take the example of login examples:

The view sends the request to the Controller, the controller finds the corresponding model, the model then connects the controller, tells the controller to succeed and fails, the controller is equivalent to having a small ledger, which records the login request successfully jumps to which page, failed to jump to which page, and then based on the response related to the page to the view.

4. Interactive model Two examples:

First, there is a configuration file, here in JSON for example, the configuration of the JSON file content is as follows:

In a file, MVC is an array name, and there is only one set of data in the array, and ActionName represents a login that loads the class in the classname below, and if it returns an OK string, Jump to the ok.jsp page, and if the error string is returned, jump to the login.jsp page.

The code for the Controller section:

Configured as *.action is to summarize all requests, so that all requests are first entered into the controller, and then the page is skipped based on the profile. The configuration file is loaded first in the initialization method, and the service method is used because the controller receives all requests, which may be a GET request or a POST request, so that all requests are received uniformly for the service method.

The code for the interface action:

Testlogin Code:

The reason for applying an interface action is to load the Testlogin class in the controller and receive the string it returns, or you can use the anti-compilation method without applying the method of the interface.

Login.jsp's Code:

Ok.jsp's Code:

Run Results Demo:

Web Architecture and MVC architecture

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.