[Question] What is MVC?

xiaoxiao2021-03-06  41

I have learned this problem a year ago, but I didn't go deep into the way.

1 explanation one

http://dev.9cbs.net/Article/52/52575.shtm

Model - View - Controller (MVC) is a software design pattern of Xerox Parc in the 1980s for programming language SMALLTALK-80, has been widely used. Recommended for Sun J2EE platform in recent years, and is popular with more and more developers using ColdFusion and PHP. Model - View - Controller mode is a useful toolbox, which has a lot of benefits, but there are also some shortcomings.

How to work MVC

MVC is a design pattern that is mandatory to separate the input, processing, and output of the application. Use the MVC application to be divided into three core components: model, view, controller. They have their own tasks.

The view view is an interface that the user sees and interacts with it. For old-fashioned web applications, the view is an interface consisting of HTML elements. In the new web application, HTML still plays an important role in the view, but some new technologies have emerged, including Macromedia Flash and Like XHTML, XML / XSL, WML, etc. Identifier language and web services.

How to handle the interface of the application becomes more challenging. MVC a big benefit is that it can handle many different views for your application. In the view, there is no real handling, regardless of the online storage or an employee list, as a view, it is just as an output data and allows the user to manipulate.

Model model represents enterprise data and business rules. In the three components of the MVC, the model has the most processing tasks. For example, it may handle the database with components like EJBS and ColdFusion Components. The data returned by the model is neutral, that is, the model is independent of the data format, so a model can provide data for multiple views. Since the code applied to the model can be reused by multiple views only, the repeatability of the code is reduced.

The controller controller accepts the user's input and calls models and views to complete the user's needs. So when you click the hyperlink and send an HTML form in the web page, the controller itself does not output anything and do anything. It just receives requests and decides which model component to deal with, and then use which view to display the data returned by the model processing.

Now we summarize the process of MVC, first control the controller to receive the user's request, and decide which model should be called to process, then model the business logic to process the user's request and return data, the last controller format the model to format the model. The data is presented to the user by means of a layer.

Why use MVC

Most of the web applications are created in procedural languages ​​like ASP, PHP, or CFML. They will mix the data layer code like the database query statement and a representation layer code like HTML. Experience is more experienced to separate data from the representation, but this is usually not easy to do, it requires careful plans and constant attempts. MVC is fundamentally mandatory to separate them. Although constructing a MVC application requires some additional work, it gives us the benefits of being unspected.

First, the most important point is that multiple views can share a model, as I mentioned, now you need to use more and more ways to access your app. In this regard, one of the solutions is to use MVC, regardless of your user wants the flash interface or WAP interface; you can handle them with a model. Since you have already separated the data and business rules from the representation, you can maximize your code.

Since the data returned by the model is not formatted, the same components can be used by different interfaces. For example, many data may be represented by HTML, but they may also be represented by Macromedia Flash and WAP. The model also has the function of state management and data persistence processing, for example, session-based shopping carts and e-commerce processes can be reused by the Flash website or wireless network. Because the model is self-contained and separated from the controller and view, it is easy to change the data layer and business rules for your application. If you want to transplant your database from MySQL to Oracle, or change your RDBMS source to LDAP, just change your model. Once you have a model correctly, the view will display correctly regardless of your data from the database or an LDAP server. Since three components that use MVC applications are mutually pertide, the change is that one of them does not affect other two, so it can construct a good pussy component based on this design idea.

For me, the controller also provides a benefit that can use the controller to connect different models and views to complete the user's needs so that the controller can provide powerful means for constructor. Given some reusable models and views, the controller can process according to the user's needs selection model, and then select the view to display the processing result to the user.

The disadvantage of MVC is that it is not easy to understand that MVC is not easy because it does not have a clear definition. Using MVC requires a careful plan, because its internal principles are more complicated, it takes some time to think.

You will have to spend a considerable time to consider how to use MVC to your application, while the model and view must be strictly separated, which also gives the debugging application have come to a certain difficulty. Each component needs to be thoroughly tested before use. Once your components have been tested, you can use them without any scruples.

Based on my personal experience, since we divide an app into three components, use MVC simultaneously means that you will manage more than before, this is obvious. This seems that our workload is increased, but remember this is not worth mentioning than the benefits that it can bring.

MVC is not suitable for small or even medium-scale applications, which takes a lot of time to apply MVC to scale is not a big application usually.

MVC is a good way to create a software MVC design mode is a way to create software. Some principles that are advocated, like content and display mutual separation may be better understood. But if you want to isolate the model, view, and controller components, you may need to think about your application, especially the architecture of the application. If you are willing to accept MVC, and you have the ability to cope with the additional work and complexity it, MVC will make your software in a new step in terms of robust, code reuse, and structure. 2 Explanation two http://www.ask321.com/ask8/ask151598.htmmodel-view-controllera. Question If you develop an enterprise application, you only need a client, then everything is very easy to solve. But the real situation is that we have to face the client, like the PDA, WAP browser and the browser running on the desktop, and we have to develop different applications to handle requests from different clients. Data Access and Reality will be confused, and repeated data access may occur, resulting in no necessary extension of the entire development cycle. b. Suggested Solution Model-View-Controller (MVC) development mode proves to be one of the effective processing methods. It can separate data access and data performance. You can develop a scalable, easy-to-extend controller to maintain the entire process. As shown in FIG. 1, the structure of the entire mode is shown. The MVC mode can be mapped to multi-layer enterprise-level J2EE applications. § All enterprise data and business logic can be used as a mode. § View can access the data by mode and display data according to the requirements of the client. The view must ensure that the data display must change at the same time when the mode changes. § The controller is used to combine mode and view to convert the client to the request to understand and execute the request, and determine the next display according to the request and execution results. Depending on the above logic, you can build an application like this: § The application's business logic is expressed in the MVC mode is EJB. The mode must handle access requests for data from the controller. § Multiple pages constitute a view in the MVC, which must be updated with the mode. § The controller is an object that receives user actions, and they convert the user's request to a pattern-understandable request and decide to display that page after the mode is processed. Figure 1c. Point § The MVC structure is suitable for those multi-user, scalable, maintainable, highly interactive systems. § MVC can express users' interaction and system mode. § It is easy to display multiple sets of data in multiple views, which is convenient to support other new client types. § The code reaches the lowest. § Due to the separation of stream control and data performance, you can divide the developer's responsibility. In addition, it can also speed up the product to introduce the market 3 Explain three http://www.chinaunix.net/bbsjh/14/1135. HTML [Repost] Understanding the MVC architecture is important for powerful web applications built with Struts

Author:

CINC Posted: 2002/12/03 08:48 AM

Understanding the MVC architecture For a powerful web application built with Struts, it is important Struts as an item of Jakarta, which provides a method that can use JavaServer Pages (JSP) and servlets together in a web application. Its purpose is to resolve inherent issues that are completely made by JSP or fully implemented by servlet. For example, Servelts can generate an HTML page, but it is very troublesome. On the other hand, JSP can be easily used in the traditional HTML page, but the JSP page has other shortcomings. In particular, it is difficult to use JSP to separate the contents of the content. It is easy to mix together with HTML with HTML, and the result is slow and difficult to maintain. However, because JSP pages are easy to use, they become the preferred method of building a dynamic web application with Java. In addition to easy programming, the JSP page is also improved, so they now overcome some of the previous limitations. JavaBeans and tag libraries are only several improvements in the foundation JSP technology. This type of method -JSP page is separately responsible for processing the request and reply client - called Model 1 architecture. JavaServer Pages are special circumstances of servlets, so both can work together to make up for each insufficient, which seems to be logical. This type of method - your web architecture contains distant but interconnected data patterns, display code and program control logic JSP and Servlet components - called Model 2 architecture, or Model-View-Controller MVC) architecture. In order to use the Struts architecture and programmed with JSP and Servlets, the understanding of the MVC architecture is necessary. The main difference between Model 1 and MVC framework is where the request is processed. In the Model 1 architecture, requests are received through JSP, mainly through JSP processing. If the JSP page needs services from any other application component, such as a database, then you will properly call from the page, return the data to the page, schedule the format of the data and display it. You can put some code in one or more JavaBeans, but this is not completely separated from the logic with it. The MVC method uses the best features of the JSP and Servlet methods, so that both technologies can work together. Clearly, servlet is a processing layer (controller). Servlet receives requests, which is very similar to the JSP page in the MODEL 1 architecture and determines how to meet those requests. This means that the request and output of the servlet control input. The business logic embodies the mode in the MVC architecture. Business logic code is handled for page. If the request to enter the servlet is a database query, the servlet transmits this request to a SQL call or a similar database code. If the request is a purchase request including the input credit card number, the matter is taken over. In a sense, the architecture of the architecture is all the reasons for the application in a leader. The JSP page is a display layer (view), which is where the user is interactive with the application. It provides input and display results. The page should not include any scripts. It just transmits data to servlet and receives and displays the returned data. The advantage of the architecture should be apparent. First, it will be clearly separated and displayed. The results are ideal, there is no processing process on the JSP page, there is no data format in servlet or business logic. Another benefit of this separation is that the Java programmer can focus on servlet code, and HTML writers can focus on JSP. Second, the controller servlet does all the decisions on the page. There will be no decisions in your page and logic.

This improves the performance and scalability of an application because requested different components that can be directed to the architecture, even different servers. The MVC architecture MVC architecture is not necessary to be the best way to use for all Java applications. As you imagine, it is often very complicated when preparing and encoding - this is unnecessary to simple applications. When the page navigation is relatively simple and fixed, and the page structure in the application can be managed by a simple directory structure, the Model 1 architecture is still the best way. These applications tend to embed the page flow information into the link between the page. (Forward in JSP "tells you that there is embedded logic in this page, let you make a decision to display the next page.) Standards for static applications with limited traffic or scalability requirements, standard JSP mode is still a viable option. In some cases, you might want to transplant a JSP application to the MVC architecture. For example, you may start with Model 1, simple JSP architecture, as your needs increase, you will find that it is too complicated or too difficult. If you spend a long time to make a relatively simple modification, if you often discover BUG in your code, then your JSP-oriented application may no longer be a proper method. With the development and changes of the application, the flow of the page and the business logic have also increased. The application becomes difficult to maintain because the page flow logic is distributed across multiple pages, and commercial logic may begin to exist in unplanned places. The best time to go to MVC from Model 1 is when these types of maintenance problems occur. You can also plan to transfer your application from an architecture to another. When the JSP page in your application contains script elements, custom tags or JavaScript to perform a Forward () operation, you may want to adjust your initial design and become a design with an MVC architecture. Refactoring is a nice term here. It refers to a technology that reconstructs the code structure in a highly rigorous manner. When your code becomes difficult to understand, modify and debug, you usually start thinking. You can use several ways to adjust the code: You can simply rename variables and methods, or transplant some code into different types of execution modes. For more information on adjustment and technology, please visit Martin Fowler's website www.refactoring.com or read the book he writes refactoring: Improving the design of existing code. In many cases, you have a meaningful MVC architecture at the beginning. For example, your application is designed for a wide range of business applications, or in a few years, your app may scale to a fairly high traffic. Designing a MVC architecture requires a deep concern. Most programmers have found a write logic script or JavaBeans, and it is easy to display with HTML. When you design a MVC architecture, you must first make a complete design. This means that the type of request that needs to be processed is analyzed to determine which components (JavaBean, Database, or other servlets) will process these requests, and how the response to those requests is displayed to the user. The key to the design is the liquidity of request and data. Designing application components for the MVC architecture is just an extension of you now using JSP and Servlets. The challenge is to build a servlet, which receives the request and divides the requests to the different components of the application. It is easy to send a database request to a database or transfer a process request to a JavaBean, but what if a request contains these two elements? Or if the nature of the request cannot be determined before some processing occurs, what? Struts architecture This challenge makes us return to the Struts architecture.

The Struts provides a highly automated way to implement the MVC architecture. Its structure implements the MVC and includes a controller servlet, a set of JSP pages, and the business logic of the application. The controller requests the user to package and directs them to other objects in the architecture. The Struts framework is surrounded by an actionmapping structure. The controller converts the user request in the form of the HTTP message into the action of the application. ActionMapping Specifies the path of the request, the scheduled object to process the request, and any other information that the request is required. ActionMApping creates an Action object to handle the request. Once an Action object has completed a task, it responds to a user request by writing results on a JSP page, or it allows an application to respond to it. http://www.chinaunix.net/bbsjh/14/1135.html

Http://www.huihoo.com/java/java_web/java-web-6.html

http://www.jdon.com/idea/application.htm

http://sunrise.x168.net/java/020712, 15,02,45.html

Http://www-900.ibm.com/developerWorks/cn/java/l-struts-mvc/index.shtml

http://www.fawcette.com/china/java/2002_04/Article.asp?page=1&xml=Strutstuff

Http://jakarta.apache.org/struts/http://dev.9cbs.net/Article/58/58688.shtm

转载请注明原文地址:https://www.9cbs.com/read-57369.html

New Post(0)