Slot 7 - MVC
Slot 7 - MVC
Servlet - Controller:
Is responsible to process the incoming request and instantiate a Model - a
Java object or a bean to compute the business logic.
Is responsible for deciding to which JSP page the request should be
forwarded.
JSP - View:
Is responsible for handling the View component.
Retrieves the objects created by the Servlet.
Extracts dynamic content for insertion within a template for display.
Advantages of Model 2:
Controller
• Manages the flow of data between the Model layer and the View layer.
• Calls methods in the Model to fulfil the requested action.
• After the action has been taken on the data in Model, the Controller is
responsible for redirecting the appropriate view to the user.
View
• Is used to generate the response to the browser, what the user sees.
• Are simple JSP or HTML pages.
Model
View and
• In this relationship, the Controller is responsiblefor creating
Controller and selecting views.
Relationship
Model and • In this relationship, the View depends on the Model.
View • If a change is made to the Model, then there might be a
requirement to make parallel changes in the View.
Relationship
Model and • In this relationship, the Controller is dependent on the Model.
Controller • If a change is made to the model interface,then there might
be a requirement to make parallel changes to the Controller.
Relationship
MVC_Lương Hoàng Hướng 15
MVC in Web Application
View shows the current state of the Model using an HTML or a JSP page.
Controller updates the state of the Model and generates one or more views
using Servlet.
DEMO
The JSP specification presents two approaches for developing Web applications namely, JSP Model I and JSP Model
II.
MVC is a software design pattern, which can be used to design medium and large sized applications.
In MVC Web application, servlet acts as Controller, which receives the request
from client.
The View handles presentation of the content on the Web page and could be an HTML file or a JSP file.