MVC Pattern (MVC Framework)
MVC Pattern (MVC Framework)
(MVC Framework)
1
Agenda
● Introduction of MVC pattern
● Evolution of Web Application design
architecture
– Model 1
– Model 2
– Application frameworks
2
Introduction to
MVC Pattern
3
MVC Pattern
4
Three Logical Layers in a Web
Application: Model
● Model (Business process layer)
– Models the data and behavior behind the
business process
– Responsible for actually doing
● Performing DB queries
● Processing orders
6
Three Logical Layers in a Web
Application: Controller
● Controller (Control layer)
– Serves as the logical connection between the
user's interaction and the business services on
the back
– Responsible for making decisions among
multiple presentations
● e.g. User's language, locale or access level dictates a
different presentation.
– A request enters the application through the
control layer, it will decide how the request
should be handled and what information should
be returned 7
Web Applications
● It is often advantageous to treat each
layer as an independent portion of your
application
● Do not confuse logical separation of
responsibilities with actual separation of
components
● Some or of the layers can be combined
into single components to reduce
application complexity
8
Evolution of Web
Application Design
Architecture
9
Evolution of MVC Architecture
1.No MVC
2.MVC Model 1 (Page-centric)
3.MVC Model 2 (Servlet-centric)
4.Web application frameworks
● Struts
5.Standard-based Web application framework
● JavaServer Faces (JSR-127)
10
Evolution of Web Application
Design until Model 1 Architecture
Response
Java 3
Bean
Servlet Enterprise
Container Information
Systems (EIS) 13
Page-centric Architecture
● Composed of a series of interrelated JSP
pages
– JSP pages handle all aspects of the application -
presentation, control, and business process
● Business process logic and control decisions
are hard coded inside JSP pages
– in the form of JavaBeans, scriptlets, expression
● Next page selection is determined by
– A user clicking on a hyper link, e.g. <A
HERF="find.jsp>
– Through the action of submitting a form, e.g. <FORM
ACTION="search.jsp"> 14
Page-centric Architecture
dataBase
response list.jsp
Client
Model
response
forward
JavaBeans
Request 2
Controller
Request 3
find.jsp
redirect
delete.jsp
16
Model 2
(Servlet-Centric
Architecture)
17
Model 2 Architecture (Servlet-
centric) MVC Design Pattern
1
Request
(Controller)
Servlet
BROWSER
In
Redirect 3 2
s
ta
nt
ia
te
5 (Model)
(View) Java Bean
Response JSP 4
19
Servlet-centric Architecture
● JSP pages are used only for presentation
– Control and application logic handled by a servlet
(or set of servlets)
● Servlet serves as a gatekeeper
– Provides common services, such as authentication,
authorization, login, error handling, and etc
● Servlet serves as a central controller
– Act as a state machine or an event dispatcher to decide
upon the appropriate logic to handle the request
– Performs redirecting
20
Servlet-centric Scenario
View
search.html
Request 1
response list.jsp
Client
Model
response
forward
JavaBeans
Request 2
Controller
Request 3
servlet
21
Web Application
Frameworks
22
Web Application Frameworks
● Based on MVC Model 2 architecture
● Web-tier applications share common set of
functionality
– Dispatching HTTP requests
– Invoking model methods
– Selecting and assembling views
● Provide classes and interfaces that can be
used/extended by developers
23
Why Web Application Framework?
● De-coupling of presentation tier and business logic into
separate components
● Provides a central point of control
● Provides rich set of features
● Facilitates unit-testing and maintenance
● Availability of compatible tools
● Provides stability
● Enjoys community-supports
● Simplifies internationalization
● Simplifies input validation
24
Why Web Application Framework?
● Frameworks have evolved with Java Server
technology
● JSP/Servlets are still hard to use
● Frameworks define re-usable components
to make this job easier.
● A good framework defines how components
work to create a usable application.
25
Web Application Frameworks
● Apache Struts
● JavaServer Faces (JSR-127)
– A server side user interface component framework
for JavaTM technology-based web applications
● Echo
● Tapestry
26
Passion!
27