MVC Introduction
- MVC begins in the desktop program, M refers to the business model, v refers to the user interface, and C is the controller.
- MVC is a pattern of creating WEB applications using MVC (Model View Controller-View-controller) design
- The MVC pattern also provides complete control over HTML, CSS, and JavaScript.
- The most typical MVC is the JSP + servlet + JavaBean pattern.
- The MVC pattern means that the software can be divided into three parts \
- Such as:
MVC two kinds of separation of implementations
Separation of view from model:
can develop different view for the same model, separate visual and non-visual components, and be able to test the model independently (only one-way reference of view to model).
The separation of the view from the controller makes it possible to test the controller independently (only one-way reference to the controller to view)
MVC the relationship between the parts:
- View Transfer command to Controller
- Controller needs Model to change state after completion of business logic
- Model sends new data to View, user gets feedback
MVC Detailed Request Process
c controls the communication between the model and view (JSP) views, and then unlocks the model-to-view coupling.
Such as:
MVC Features of:
1. Low coupling
The three components of an MVC application are independent, changing one does not affect the other two, so a good loosely coupled component can be constructed based on this design idea
2. High re-usability
The MVC pattern allows you to access the same server-side code using a variety of different styles of views, because multiple view can share a model;
3. High maintainability
Separating the view layer and the business Logic layer also makes Web applications easier to maintain and modify
1. No definite definition
It's not easy to fully understand MVC, and every component needs to be thoroughly tested before it can be used.
2, not suitable for small, medium-sized applications
It takes a lot of time to apply MVC to applications that are not large in size and often outweigh the costs
3. The connection between the view and the controller is too tight
Views and controllers are separated from each other, but are tightly connected parts, the view has no controller, its application is very limited, and vice versa, which hinders their independent reuse.
Java Web The main components of the application
- Servlet components
- The servlet runs in a web container, such as Tomcat.
- . JSP components
- JSP is a Dynamic Web page technology.
- JavaBean components
- The JavaBean component is a Java object that conforms to a specific specification.
- The Web container passes information through ServletRequest objects and Servletresponse objects and methods, and then parses the returned information to the browser
- The browser translates the JSP into a Java file to compile and produce HTML.
- Use this component to store some intermediate data. For example, ServletRequest request information, query from the database
Java Web Solution Solutions
- Jsp+servlet+javabean Development mode: JSP as a view to the performance of the page, Servlet as a controller, control program process and call the business processing; JavaBean encapsulates the business logic. Followed the MVC design pattern.
- Struts+spring+hibernate Development Program:
- Struts is responsible for the presentation layer,
- Spring is responsible for the business of the logic layer,
- Hibernate database operations in persistent layer,
- The development plan of the composition.
The commonly used Javaweb MVC framework
- Struts is an MVC framework based on the Sun EE platform, which is mainly implemented by servlet and JSP technology.
- Struts consolidates Servlets, JSPs, custom tags, and information (messageresources) into a unified framework that developers can use to develop without having to code their own full set of MVC patterns, saving time.
Spring MVC,
The Springweb MVC Framework (abbreviated as SPRINGMVC) is a rich Model View Control Web framework. It publishes request processing by using the dispatcher servlet, which uses configurable handler mappings, view resolution, and theme solutions.
Course assignments for the MVC framework