Here I will use my blog example written using Servlet, and then use the functions provided by the files in the example to correspond to the corresponding part of the MVC pattern. I will not describe the details here.
Let me briefly introduce the MVC mode:
M is the exponential data model, V refers to the user interface, and C is the controller. The purpose of using MVC is to separate the implementation code of M and V, so that the same program can use different forms of representation. The purpose of C is to ensure synchronization between m and V. Once M changes, V should be updated synchronously.
The most typical MVC is the JSP + servlet + JavaBean mode. My blog example uses this mode.
Below I will correspond to MVC Based on my example:
First, a full file directory:
Here is the file required by my project.
V (User Interface ):
Only a part of JSP files are listed here. The JSP file corresponds to V (User Interface). We can enter information on the interface, such as search information and user login.
C (Controller ):
I am using Servlet here (I will not go into details about some of the Servlet's usage and configuration details here. There is a lot of information on the Internet .)
Servlet is used for command and calling methods.
The main workflow of servlet is two methods: doget () and dopost. Call different methods in the doget () method based on different situations.
M (Data Model ):
Equivalent to JavaBean
Dao contains specific methods, such as connecting to the database for searching and updating.
In form, object attributes and corresponding get and set methods are stored.
Tool contains some tool classes, such as character replacement and database connection.
After this blog study, I have summarized my understanding of MVC.:MVC is equivalent to playing a music, C is the conductor, V is the performer and its instrument, M is the audience, the conductor directs the performers to play, the audience to enjoy.