Introduction to MVC Patterns

Source: Internet
Author: User

The full name of MVC is the model View Controller, which is the abbreviation for the models-view-controller, a software design paradigm that organizes the code with a method of business logic, data, and interface display separation. Aggregating business logic into a single component does not require rewriting business logic while improving and personalizing the interface and user interaction. MVC is uniquely developed to map the traditional input, processing, and output functions in a logical graphical user interface structure.

MVC begins in the desktop program, M refers to the business model, v refers to the user interface, C is the controller, the purpose of using MVC is to separate m and v implementation code, so that the same program can use different representations. For example, a batch of statistical data can be represented by histogram, pie chart. C exists to ensure the synchronization of M and V, and once M is changed, V should be updated synchronously.

M = model = (USERMANAGER+USERMANAGERIMPL+USER+USERDAO+USERDAOIMPL) +db
V = view = JSP
C = Controller = Struts2fileter+action

Model (models) represent the core of the application (such as a list of database records).

View displays data (database records).

The controller (Director) processes the input (writes to the database record).

The MVC pattern also provides complete control over HTML, CSS, and JavaScript.

Model is the part of your application that handles application data logic.
Typically, model objects are responsible for accessing data in the database.

View is the part of the application that handles the display of data.
Typically views are created from model data.

A controller is a part of an application that handles user interaction.
Usually the controller is responsible for reading data from the view, controlling user input, and sending data to the model.

MVC refers to some kind of framework of the MVC pattern, which makes it mandatory to separate the input, processing, and output of the application. Using an MVC application is divided into three core parts: model, view, controller. Each of them handles their own tasks. The most typical MVC is the JSP + servlet + JavaBean pattern.

The main components of a Java Web application

1.Servlet components

Servlets run in web containers, such as Tomcat, which can be dynamically loaded by the Web container, receive browser requests, invoke other components to process requests, and then return the processing results.

When a browser accesses a servlet, the Web container creates a ServletRequest object and a servlet response object, and encapsulates the user's request information in the Servlet request object. The two objects are then transferred as parameters to the specific method of the servlet. In this method, the request is processed, the processing result is encapsulated in the Servlet response object, and returned to the Web container. Finally, the Web container returns the results to the browser to parse and display.

2.JSP components

JSP is a Dynamic Web page technology. It adds Java scripts to the HTML page, and JSP tags make up the jsp file. When a browser requests a JSP page, Tomcat translates the JSP page into a Java file. It then compiles it into a class file, executes it, and returns the resulting HTML page to the client display.

3.JavaBean components

The JavaBean component is a Java object that conforms to a specific specification. A series of properties are defined in the JavaBean component, and each property provides a setter and getter method so that you can use the component to store some intermediate data. For example, request information from the Servlet requests, information queried from the database, and so on.

4.EJB components

Enterprise java Bean (EJB) components are server-side Java components. This component is based on standard distributed object Technology, CORBA and RMI technologies, and is used to implement business logic for enterprise applications. The design goal and core application is to deploy distributed applications. In simple terms, a program that has already been written (that is, a class) is packaged and placed on the server for execution.

5.XML language

XML (extensible Markuplanguage) is a markup language used to create custom tags.

6.Web Server and Application server

The Web server is used to process HTTP requests and return HTTP data. It is mainly used to interact with the browser to provide services to the user. The application server can be called by the Web server to handle the business logic. The data it returns is organized into HTML format by the Web server and then returned to the browser to parse.

Java Web solution (development method)

1.jsp+javabean Development Mode:

This mode separates the business logic from the performance of the page, and increases the debugging and maintainability of the program to some extent. But the page will be controlled and displayed in a set. Although simple, knowledge is suitable for the rapid construction and operation of small projects.

2.jsp+servlet+javabean Development Mode:

The JSP acts as a view to represent the page; The servlet acts as a controller, the process of controlling the program and invokes the business; JavaBean encapsulates the business logic. Followed the MVC design pattern. MVC is implemented, but no unified development framework results in a long development cycle.

3.struts+spring+hibernate

Struts is responsible for the presentation layer, spring is responsible for the business of the logic layer, Hibernate persistent layer database operation, is a set of mature and stable development plan.

Introduction to MVC Patterns

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.