mvc pattern (mvc framework)repository.binus.ac.id/2009-1/content/t0053/t005394929.pdf ·...
TRANSCRIPT
![Page 1: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/1.jpg)
1
MVC Pattern MVC Pattern (MVC Framework)(MVC Framework)
![Page 2: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/2.jpg)
2
Agenda
● Introduction of MVC pattern● Evolution of Web Application design
architecture– Model 1– Model 2– Application frameworks
![Page 3: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/3.jpg)
3
Introduction to Introduction to MVC PatternMVC Pattern
![Page 4: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/4.jpg)
4
MVC Pattern
![Page 5: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/5.jpg)
5
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● Calculating the business process● Processing orders
– Encapsulate of data and behavior which are independent of presentation
![Page 6: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/6.jpg)
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 was
obtained, or from where (since that is the responsibility of Model)
![Page 7: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/7.jpg)
7
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
![Page 8: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/8.jpg)
8
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
![Page 9: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/9.jpg)
9
Evolution of Web Evolution of Web
Application Design Application Design ArchitectureArchitecture
![Page 10: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/10.jpg)
10
Evolution of MVC Architecture
1.No MVC2.MVC Model 1 (Page-centric)3.MVC Model 2 (Servlet-centric)4.Web application frameworks
● Struts5.Standard-based Web application framework
● JavaServer Faces (JSR-127)
![Page 11: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/11.jpg)
11
Evolution of Web Application Design until Model 1 Architecture
Model 1 architectureNo MVC
![Page 12: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/12.jpg)
12
Model 1Model 1(Page-Centric (Page-Centric Architecture)Architecture)
![Page 13: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/13.jpg)
13
Model 1 Architecture (Page-centric)
Request1
JSPpages
Java Bean
Response
4
2
3
BR
OW
SER
Servlet Container
Enterprise Information
Systems (EIS)
![Page 14: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/14.jpg)
14
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">
![Page 15: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/15.jpg)
15
Page-centric Architecture
memu.jsp catalog.jsp checkout.jsp
dataBase
page–centric catalog application
![Page 16: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/16.jpg)
16
Page-centric Scenario
Client
View
search.html
list.jsp
Model
JavaBeansController
find.jsp
delete.jsp
redirect
forward
Request 1
Request 2
Request 3
response
response
![Page 17: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/17.jpg)
17
Model 2(Servlet-Centric
Architecture)
![Page 18: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/18.jpg)
18
Model 2 Architecture (Servlet-centric)
Request1
(Controller)Servlet
(View)JSPResponse
5
3
4
BR
OW
SER
Servlet Container (EIS)
Redirect 2
(Model)Java Bean
Instantiate
MVC Design Pattern
![Page 19: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/19.jpg)
19
Why Model 2 Architecture?● What if you want to present different JSP
pages depending on the data you receive?– JSP technology alone even with JavaBeans and
custom tags (Model 1) cannot handle it well● Solution– Use Servlet and JSP together (Model 2)– Servlet handles initial request, partially process the
data, set up beans, then forward the results to one of a number of different JSP pages
![Page 20: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/20.jpg)
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 decide
upon the appropriate logic to handle the request– Performs redirecting
![Page 21: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/21.jpg)
21
Servlet-centric Scenario
Client
View
search.html
list.jsp
Model
JavaBeansController
forward
Request 1
Request 2
Request 3
response
response
servlet
![Page 22: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/22.jpg)
22
Web ApplicationFrameworks
![Page 23: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/23.jpg)
23
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
![Page 24: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/24.jpg)
24
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
![Page 25: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/25.jpg)
25
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.
![Page 26: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/26.jpg)
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
![Page 27: MVC Pattern (MVC Framework)repository.binus.ac.id/2009-1/content/T0053/T005394929.pdf · 2009-08-05 · MVC Pattern (MVC Framework) 2 Agenda ... – Use Servlet and JSP together (Model](https://reader030.vdocuments.site/reader030/viewer/2022033123/5e5ada2c1c5319226c30e0b9/html5/thumbnails/27.jpg)
27
Passion!