Upload
duongtuanvn
View
286
Download
2
Embed Size (px)
Citation preview
8/14/2019 MVC Pattern (MVC Framework)
1/27
1
MVC PatternMVC Pattern
(MVC Framework)(MVC Framework)
8/14/2019 MVC Pattern (MVC Framework)
2/27
2
Agenda Introduction of MVC pattern
Evolution of Web Application designarchitecture Model 1
Model 2
Application frameworks
8/14/2019 MVC Pattern (MVC Framework)
3/27
3
Introduction toIntroduction to
MVC PatternMVC Pattern
8/14/2019 MVC Pattern (MVC Framework)
4/27
4
MVC Pattern
8/14/2019 MVC Pattern (MVC Framework)
5/27
5
Three Logical Layers in a Web
Application: Model
Model (Business process layer)
Models the data and behaviorbehind thebusiness process
Responsible for actually doing
Performing DB queries
Calculating the business process Processing orders
Encapsulate of data and behavior which areindependent of presentation
8/14/2019 MVC Pattern (MVC Framework)
6/27
6
Three Logical Layers in a Web
Application: View
View (Presentation layer)
Display information according to client types Display result of business logic (Model)
Not concerned with how the information wasobtained, or from where (since that is the
responsibility of Model)
8/14/2019 MVC Pattern (MVC Framework)
7/277
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 onthe back
Responsible for making decisions amongmultiple presentations
e.g. User's language, locale or access level dictates adifferent presentation.
A request enters the application through thecontrol layer, it will decide how the request
should be handled and what information shouldbe returned
8/14/2019 MVC Pattern (MVC Framework)
8/278
Web Applications
It is often advantageous to treat eachlayer as an independent portion of yourapplication
Do not confuse logical separation ofresponsibilities with actual separation ofcomponents
Some or of the layers can be combinedinto single components to reduceapplication complexity
8/14/2019 MVC Pattern (MVC Framework)
9/279
Evolution of WebEvolution of WebApplication DesignApplication Design
ArchitectureArchitecture
8/14/2019 MVC Pattern (MVC Framework)
10/2710
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)
8/14/2019 MVC Pattern (MVC Framework)
11/27
11
Evolution of Web Application
Design until Model 1 Architecture
Model 1 architectureNo MVC
8/14/2019 MVC Pattern (MVC Framework)
12/27
12
Model 1Model 1
(Page-Centric(Page-CentricArchitecture)Architecture)
8/14/2019 MVC Pattern (MVC Framework)
13/27
13
Model 1 Architecture (Page-
centric)
Request
1
JSP
pages
JavaBean
Response
4
2
3
BROWSER
Servlet
Container
Enterprise
InformationSystems (EIS)
8/14/2019 MVC Pattern (MVC Framework)
14/27
14
Page-centric Architecture
Composed of a series of interrelated JSPpages
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.
8/14/2019 MVC Pattern (MVC Framework)
15/27
15
Page-centric Architecture
memu.jsp catalog.jsp checkout.jsp
dataBase
pagecentric catalog application
8/14/2019 MVC Pattern (MVC Framework)
16/27
16
Page-centric Scenario
Client
View
search.html
list
.jspModel
JavaBeans
Controller
find.jsp
delete.jsp
redirect
forward
Request 1
Request 2
Request 3
response
response
8/14/2019 MVC Pattern (MVC Framework)
17/27
17
Model 2
(Servlet-CentricArchitecture)
8/14/2019 MVC Pattern (MVC Framework)
18/27
18
Model 2 Architecture (Servlet-
centric)
Request
1
(Controller)Servlet
(View)JSPResponse
5
3
4
BROWSER
Servlet Container (EIS)
Redirect2
(Model)Java Bean
Insta
ntia
te
MVC Design Pattern
8/14/2019 MVC Pattern (MVC Framework)
19/27
19
Why Model 2 Architecture?
What if you want to present different JSPpages depending on the data you receive?
JSP technology alone even with JavaBeans andcustom tags (Model 1) cannot handle it well
Solution Use Servlet and JSP together (Model 2)
Servlet handles initial request, partially process thedata, set up beans, then forward the results to oneof a number of different JSP pages
8/14/2019 MVC Pattern (MVC Framework)
20/27
20
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 decideupon the appropriate logic to handle the request
Performs redirecting
8/14/2019 MVC Pattern (MVC Framework)
21/27
21
Servlet-centric Scenario
Client
View
search.html
list.jsp
Model
JavaBeans
Controller
forward
Request 1
Request 2
Request 3
response
response
servlet
8/14/2019 MVC Pattern (MVC Framework)
22/27
22
Web ApplicationFrameworks
8/14/2019 MVC Pattern (MVC Framework)
23/27
23
Web Application Frameworks
Based on MVC Model 2 architecture
Web-tier applications share common set offunctionality Dispatching HTTP requests
Invoking model methods
Selecting and assembling views
Provide classes and interfaces that can beused/extended by developers
8/14/2019 MVC Pattern (MVC Framework)
24/27
24
Why Web Application Framework?
De-coupling of presentation tier and business logic intoseparate 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
8/14/2019 MVC Pattern (MVC Framework)
25/27
25
Why Web Application Framework?
Frameworks have evolved with Java Servertechnology
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.
8/14/2019 MVC Pattern (MVC Framework)
26/27
26
Web Application Frameworks
Apache Struts
JavaServer Faces (JSR-127) A server side user interface component framework
for JavaTM technology-based web applications
Echo
Tapestry
8/14/2019 MVC Pattern (MVC Framework)
27/27
27
Passion!