Transcript Document

Chapter 3
Web
Technologies
Figures
3.1 I nt roduct ion
Client
tier
47
Presentation
Presentation
Presentation
Presentation
Presentation
Pres. logic
Pres. logic
Pres. logic
Pres. logic
App. logic
App. logic
Data
Web 2.0
(2005-today)
Distributed
web
application
Web 1.0
(1990s-2005)
Client-server
(1970s-1990s)
Time
Mainframe
(1940s-1970s)
Web
server tier
Pres. logic
Pres. logic
App. logic
App. logic
App. logic
App. logic
Data
Data
Data
Data
Data
F i g. 3.1 T he change of t he dist ri but ion of a web applicat ion’s int ernal archit ect ural
layers over client and server over t ime (adapt ed from ht t p: / / www. coachwei . com).
However, very oft en mashups also adopt a server-side logic. In some cases,
© Copyrightt 2014
by F.isDaniel
M. Matera.
classroom
he server
exploitand
ed only
for t he Reproduction
st orage of t he for
resources
(e.g.,use
t heand
HT teaching
ML
3.2 T he I nt ernet
49
Mobile telephone network
Mobile
devices
Backbone
Server farm
Web server
NAP
Router
Regional ISP
WiFi router
Notebook
Telephone system
POP
DSL
modem
Desktop workstation
Web/
email server
Distributed web application
Email server
F i g. 3.2 I nt ernet archit ect ur e (adapt ed from [259]). T he dashed polygon describes
a possible dist ribut ion of a web applicat ion over t he I nt ernet .
rout e t raffic from one node t he anot her. If a packet is dest ined for a host
side t he
regional
ISP’sReproduction
network, t heforISP
hands ituse
over
t he
© Copyright running
2014 by out
F. Daniel
and
M. Matera.
classroom
andt oteaching
© Copyright 2014 by F. Daniel and M. Matera. Reproduction for classroom use and teaching
© Copyright 2014 by F. Daniel and M. Matera. Reproduction for classroom use and teaching
© Copyright 2014 by F. Daniel and M. Matera. Reproduction for classroom use and teaching
3.7.1 Ser vlet s
An example of ext ended Web server archit ect ure is Javasoft’s Servlet API (illust rat ed in Figure 3.6), which associat es t he Web server wit h a Java Virt ual
Machine (JVM). T he JVM support s t he execut ion of a special Java program,
t he servlet container, which in t urn is in charge of managing session dat a and
execut ing Java servlets.
HTTP request
Request parameters
Generated page
HTTP response
Client (browser)
Web server
Servlet container
F i g. 3.6 Java servlet archit ect ure.
© Copyright 2014 by F. Daniel and M. Matera. Reproduction for classroom use and teaching
Java servlet s. A JSP page is composed of blocks of st at ic code (HT ML,
JavaScript , CSS, et c.), mixed wit h dynamic blocks, i.e., port ions of Java
code execut ed by t he script ing engine.
Client (browser)
Request for index.jsp
HTML response
Web server
JSP to servlet
translation
Servlet
compilation
Servlet
execution
F i g. 3.7 T he t ranslat ion of JSP pages int o servlet s.
Each t ime t he Web server receives a request for a same JSP page, it verifies
whet her changes t o it s code occurred since it s creat ion by checking t he cont ent
of t he Last Modi f i ed HT T P header. If not , t he servlet inst ance for t hat
page st ored in memory is recalled; ot herwise, t he JSP page is recompiled and
a new servlet inst ance is creat ed and st ored in memory. For t his reason, t he
first access t o a JSP page requires a longer t ime (t he so-called first-person
© Copyright penalty),
2014 by F.
Daniel
M. Matera.
Reproduction
while
t heand
following
request
s are fast er. for classroom use and teaching
whet her changes t o it s code occurred since it s creat ion by checking t he cont ent
of t he Last Modi f i ed HT T P header. If not , t he servlet inst ance for t hat
page st ored in memory is recalled; ot herwise, t he JSP page is recompiled and
a new servlet inst ance is creat ed and st ored in memory. For t his reason, t he
first access t o a JSP page requires a longer t ime (t he so-called first-person
penalty), while t he following request s are fast er.
Directives
<%@page contentType=”text/html”%>
JSP
JSP page
Scripting elements
<% int a=1; %>
Actions
<%jsp:include page=”includeme.jsp”%>
F i g. 3.8 T he st ruct ure of JSP pages.
© Copyright 2014 by F. Daniel and M. Matera. Reproduction for classroom use and teaching
t erlayer communicat ion. Application servers provide such an environment .
By providing an int ermediat e layer between t he Web server and t he back-end
for resource management , t hey enable t he efficient execut ion of component s
in t he applicat ion logic layer, t hus support ing t he const ruct ion of dynamic
pages according t o t he execut ion flow depict ed in Figure 3.9.
1. HTTP
request
2. Script
request
3. Component
call
4. Query
Database server
Client
8. HTTP
response
Web
server
7. HTML
page
Scripting
engine
6. Answer
5. Results
Application
server
Legacy systems
F i g. 3.9 A pplicat ion server archit ect ure
T he Web server accept s t he HT T P request coming from t he client and
t ransforms it int o a request t o t he script ing engine. T he script ing engine
execut es t he program associat ed wit h t he request ed URL, which may also
include calls t o business component s host ed in t he applicat ion server. Typically, such calls involve t he ret rieval and elaborat ion of dat a from one or
more dat a sources, such as corporat e dat abases, legacy syst ems or ext ernal
Web services. T he component s managed by t he applicat ion server dispat ch
© Copyright 2014 by F. Daniel and M. Matera. Reproduction for classroom use and teaching
70
3 Web Technologies
requests
Controller
modifies
Web Pag e Titl e
Client
browser
selects
responds
View
Model
notifies state
F i g. 3.10 T he M odel-V iew-Cont roller pat t ern adapt ed t o Web applicat ions.
If a user issues a page request t o t he Web applicat ion, t he request is int ercept ed by t he Cont roller, which is in charge of deciding which business
operat ion needs t o be performed. T he Cont roller, hence, invokes t he respect ive component in t he Model, which cont ains t he necessary logic t o execut e
t he request ed act ion, t o updat e t he st at e of t he applicat ion, and t o assemble
t he dat a t o be present ed t o t he user. T he change of t he applicat ion st at e
act ivat es t he View, which fills t he present at ion t emplat e wit h t he dat a comput ed by t he Model. Finally, t he so-const ruct ed HT ML response is sent t o
© Copyright 2014 by F. Daniel and M. Matera. Reproduction for classroom use and teaching
© Copyright 2014 by F. Daniel and M. Matera. Reproduction for classroom use and teaching