[JAVA] Learn more clearly with diagrams !! Model structure of Web application What is MVC model?

What is an MCV model?

When developing a web application, create a combination of ** Servlet class ** and ** JSP file **. It can be developed efficiently by combining them. The ** MVC model ** is used as a reference when developing in combination. In other words ... ** Something like a model or guideline for the internal structure of an application. ** ** To say a little more ... ** An exemplary structure for GUI applications **. Web applications using Servlets and JSPs are also basically GUI applications.

Three elements of development in MVC model

The MVC model develops the application by dividing it into three elements (model, view, controller). The roles are summarized in the table below.

element role
model(Model) The main processing of the application(Calculation processing etc.)And data storage etc.
View(View) Display the screen to the user
controller(Controller) Receives a request from the user, asks the model to perform the process, and asks the view to display the result.

Each element has a specific role to play, and does not play the role of other elements. By dividing the roles, it becomes clear which element should be modified when modifying or extending the processing, and it becomes easier to maintain or extend the application itself.

These elements work together to provide the functionality of the application to the user.

Realizing the MVC model in web applications

Untitled Diagram.jpg

** Controller is in charge of Servlet class ** The ** Servlet class ** is in charge of the ** controller ** that receives requests from users and controls the entire system. Requests can also be made in JSP files, but the controller role requires complex control and exception handling. Java-based Servlet classes are better suited for such processing.

** Model is in charge of Java class ** The general ** Java class ** is in charge of the process that responds to the user's request (search, etc.) and the ** model ** that represents the data (search terms and search results) related to that process. A general class here is a class that does not include classes or interfaces related to Web applications such as HttpServletRequest. ** Advantages **: Even programmers with no knowledge of web applications can participate in model development.

** View is in charge of JSP file ** The ** view ** that outputs is handled by the ** JSP file ** that specializes in HTML output. You can also output with the Servlet class, but the process becomes complicated because it requires a large number of println () methods. ** Advantage **: JSP files can be written as HTML, so web page designers can design without Java knowledge.

References

Daigo Kunimoto "Introduction to Servlet & JSP that can be understood clearly, 2nd edition" Impress Corporation, 2019

Recommended Posts

Learn more clearly with diagrams !! Model structure of Web application What is MVC model?
What is MVC model?
What is the data structure of ActionText?
What is the Java Servlet / JSP MVC model?
The official name of Spring MVC is Spring Web MVC
Roughly the flow of web application development with Rails.
What is web development?
What is the representation of domain knowledge in the [DDD] model?
Spring5 MVC Web application development with Visual Studio Code Environment construction (Installation of JDK11, Maven, Tomcat, Visual Studio Code)