A single server supports tion is port 80 is the def ault, and as luck ault Server : The unique name of the physical server youÕre looking for.. Because mos t of the early servers on
Trang 2ALREADY THIS 9OU THESE CHAPTER
&RYHUDJH1RWHV
Copyright Safari Books Online #747221
Trang 3to build a web application that cli ents around the globe can access And t o become obscenely rich
6HUYHU
6HUYHU
Trang 4The serverÕs response contains the actual document that the cli ent requested (or an error code if the request could not be proc
it can send to cli ents
That content can be web pages, JPEGs, and other resources.
Trang 7DElNE A
CENTER
DElNE THE
DElNE DElNE DElNES
A THE
(Technically, the <center> and <a lign> tags have been deprecated in HTML 4.0, but weÕr e using them in some of our examples because i tÕs simpler to read than the alterna tive, and youÕre not here to learn HTML anyway.)
Trang 8we want it (Remember,
<align> is depreca ted, but weÕre using it because i tÕs simple to read.)
in the form.
?PI\aW]_ZQ\M
\PM0<54
The <br> tags cause line breaks
An HTML comment
<RXQHHGRQO\WKHPRVWEDVLF+70/
NQRZOHGJH
(4-,NOT(4-,THOUGH HAPPENING
ZULWLQJ+70/
Trang 11\RXDUHKHUH
0<54Q[XIZ\WN\PM0<<8ZM[XWV[M
!NINFORMATIONOTHERBROWSEROF
When the browser Þ nds the opening <html> tag it goes into HTML-rendering mode and displays the page to the user.
Trang 15\RXDUHKHUH
)VI\WUaWNIV0<<8/-<ZMY]M[\
*(7VHOHFWVHOHFW%HHU7DVWHMVS"FRORU GDUN WDVWH PDOW\+773
+RVWZZZZLFNHGO\VPDUWFRP8VHU$JHQW0R]LOOD0DFLQWRVK833&0DF26;0DFK2HQ86UY *HFNR
1HWVFDSH
$FFHSWWH[W[PODSSOLFDWLRQ[PODSSOLFDWLRQ[KWPO[POWH[WKWPOT WH[W
$FFHSW/DQJXDJHHQXVHQT
$FFHSW(QFRGLQJJ]LSGHӿDWH.HHS$OLYH
The path to the resource on the web server that the web browser The protocol version
is requesting.
The Request headers.
Trang 16FKDSWHU
3267DGYLVRUVHOHFW%HHU7DVWHGR+773
+RVWZZZZLFNHGO\VPDUWFRP8VHU$JHQW0R]LOOD0DFLQWRVK833&0DF26;0DFK2HQ86UY *HFNR
1HWVFDSH
$FFHSWWH[W[PODSSOLFDWLRQ[PODSSOLFDWLRQ[KWPO[POWH[WKWPOT WH[W
$FFHSW/DQJXDJHHQXVHQT
$FFHSW(QFRGLQJJ]LSGHӿDWH.HHS$OLYH
The HTTP Method on the web serv The path to the r esource
er.
The protocol v ersion that the web browser is reques ting.
The message body,
This time, the parameter
s are down here
in the body, so they arenÕt limited the way they are if you use a GET and hav
Trang 17\RXDUHKHUH
)VI\WUaWNIV0<<8ZM[XWV[MIVL
_PI\\PMPMKSQ[I¹515-\aXMº'
the status code.
Notice that the MIME type value relates to the values listed in the HTTP requestÕs ÒAcceptÓ header
(Go look at the Accept header from the previous pageÕs POST request.)
Trang 18to the browser.
And generates an HTTP response.
The server Þ nds the page
The HTTP GET is sent t o the serv
er.
The browser creates an HTTP GET request.
The browser renders the HTML.
*MMZP\UT
The user types a URL.
*(7WHVW%HHUKWPO+773
+RVWZZZZLFNHGO\VPDUWFRP8VHU$JHQW0R]LOOD0DFLQWRVK
UHTXHVWDQGUHVSRQVH
KWWSZZZZLFNHGO\VPDUWFRPWHVW%HHUKWPO
Trang 20optional A single serv
er supports
tion is
port 80 is the def
ault, and as luck
ault
Server : The unique name of the physical server youÕre looking for This name maps to a unique
IP address IP addresses are numeric and take the form Òxxx.
yyy.zzz.aaaÓ You can specify an
IP address here instead of a server name, but a server name is a lot easier to remember.
Path : The path to the location,
on the server, of the resourc e being requested Because mos t of the early servers on the web ran Unix, Unix syntax is still used t o describe the directory hierarchi es
on the web server.
Protocol: Tells the
server which communications
protocol (in this case
HTTP) will be used.
Resource : The name of the content being requested This could be an HTML page, a servlet, an image, PDF, music, video, or anything else the server feels like serving If this optional part of the URL is left out, most web servers will look for index.html by default.
DQDWRP\RID85/
Optional Query Str ing
: Remember, if this was a GET request, the ex
tra info (parameters) would be app
ended
to the end of this URL, s
tarting with a question mark Ò?Ó, and wi
th each parameter (name/v
alue pair) separated by an amp
ersand Ò Ó.
Not shown:
Trang 21HTTP HTTPS
SRUWVIRU\RXURZQ
FXVWRPVHUYHUSURJUDPV
Using one server app per port, a server can have up to 65536 different server apps running (although itÕs possible to run more than one app on the same port if the apps use different protocols).
Trang 22EHHU$GYLFH VNLLQJ$GYLFH
KWGRFV
$SDFKHBKRPH
FKHFNRXW
,QGH[KWPO ,QGH[KWPO
Òindex.htmlÓ is the default
page that will be returned
to a user who keys
Òwww.wickedlysmart.com/Ó
into his browser.
The root folder
application.
An Apache server will assume that ÒhtdocsÓ is the directory that is the root for all of the serverÕs web applications.
The two applications on this server.
The folders for the beerAdvice appÕs two actions.
Òindex.htmlÓ is the default page for the
that gives the user some advice.
Trang 24These pages go straight
to the client just exactly as they were put on the server.
Trang 28FKDSWHU
;MZ^TM\[IVL+/1JW\PXTIa\PMZWTMWNI
PMTXMZIXXQV\PM_MJ[MZ^MZ
,ISTENPROS
0ERFORMANCE TOREQUEST
!H REQUESTSSEPARATENOAND
)SERVERSSPECIALPROGRAMS
INA
)CLIENTCONTAINERRIGHT
TO
WZRVLGHV&*,DQG6HUYOHWV
Trang 29+RVWZZZZLFNHGO\VPDUWFRP8VHU$JHQW0R]LOOD0DFLQWRVK
KWWSZZZZLFNHGO\VPDUWFRPWHVW%HHUKWPO5HTXHVW
Trang 30Highlights:
-One DD per web applica tion.
-A DD can declare man y servlets.
- A <servlet-name> ti es the
<servlet> element to the mapping> element.
<servlet A <servlet<servlet class> is the Jav a class.
- A <url-pattern> is the name the client uses for the reques t.
Trang 31(This is all one command.)
Trang 32int
tream (itÕs really part of the HTTP r
GOOD
PAGEEASIERAND
%XCEPT
2EMEMBER ONE ABOUT
+70/LQDSULQWOQ VXFNV
Trang 379OU THESE CHAPTER
%NJOY WHILE
"54
MOVING EXPERIENCE PAGES MOVE
&RYHUDJH1RWHV
Copyright Safari Books Online #747221
Trang 39ING MENT
Trang 40LOGICFROM
AUTOMATICALLYREQUESTTHETHREADOFFSYNCHRONIZATIONMANAGEOF
7ELL ...
ZULWLQJ+70/
Trang 11\RXDUHKHUH
0<54Q[XIZ\WN\PM0<<8ZM[XWV[M... header from the previous pageÕs POST request.)
Trang 18to the browser.
And. .. requesting.
The Request headers.
Trang 16FKDSWHU
3267DGYLVRUVHOHFW%HHU7DVWHGR+773