FKDSWHU
5MUWZQbQVO\PM-2*ZMTI\ML,,\IO[
4HISEXAMISABOUTWEBCOMPONENTSNOTBUSINESSCOMPONENTSALTHOUGHINTHE
0ATTERNSCHAPTERYOULLSEEAFEWTHINGSABOUTBUSINESSCOMPONENTS"UTIFYOURE
DEPLOYINGA*%%APPCOMPLETEWITH%NTERPRISE*AVA"EANS%*"SINTHEBUSINESS
TIERSOMEOFYOURWEBCOMPONENTSWILLPROBABLYNEEDTOLOOKUPANDACCESSTHE
ENTERPRISEBEANS)FYOUREDEPLOYINGANAPPINAFULL*%%COMPLIANT#ONTAINER
ONETHATHASAN%*"#ONTAINERASWELLYOUCANDElNEREFERENCESTO%*"SINTHE
$$9OUDONTHAVETOKNOWANYTHINGABOUT%*"SFORTHISEXAMOTHERTHANWHATYOU
DECLAREINTHE$$SOWEWONTWASTEYOURTIMEEXPLAININGITHERE
"UTIFYOUREINTERESTEDIN%*"THERESTHISREALLYGOODBOOK
HMEORFDOUHI!
HMEUHIQDPH!HME&XVWRPHUHMEUHIQDPH!
HMEUHIW\SH!(QWLW\HMEUHIW\SH!
ORFDOKRPH!FRPZLFNHGO\VPDUW&XVWRPHU+RPHORFDOKRPH!
ORFDO!FRPZLFNHGO\VPDUW&XVWRPHUORFDO!
HMEORFDOUHI!
5HIHUHQFHWRDORFDOEHDQ
-90
6HUYOHW
$/2&$/EHDQPHDQVWKHFOLHQWLQ
WKLVFDVHDVHUYOHWDQGWKHEHDQ
PXVW
EHUXQQLQJLQWKHVDPH-90
$5(027(EHDQPHDQVWKHFOLHQWLQ
WKLVFDVHDVHUYOHWDQGWKHEHDQFDQ
EHUXQQLQJLQGLIIHUHQW-90VSRVVLEO\
RQGLIIHUHQWSK\VLFDOPDFKLQHVDVZHOO
HMEUHI!
HMEUHIQDPH!HME/RFDO&XVWRPHUHMEUHIQDPH!
HMEUHIW\SH!(QWLW\HMEUHIW\SH!
KRPH!FRPZLFNHGO\VPDUW&XVWRPHU+RPHKRPH!
UHPRWH!FRPZLFNHGO\VPDUW&XVWRPHUUHPRWH!
HMEUHI!
5HIHUHQFHWRDUHPRWHEHDQ
-90
6HUYOHW
-90
(Optional sub-elements for both tags include
<description> and <ejb-link>, but you donÕt
need to know that for the exam.)
These must be fully-qualiÞed names
of the beanÕs exposed interfaces.
The JNDI lookup name
youÕll use in code.
FRQ¿JXULQJ(-%UHIHUHQFHV
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
%RWKWKHORFDODQGUHPRWHEHDQ''WDJVKDYHWZRHOHPHQWV
WKDWDUHWKHVDPH
7KHHMEUHIQDPH!WKDWOLVWVWKHORJLFDOORRNXSQDPH
\RX¶OOXVHLQFRGHWRSHUIRUPD-1',ORRNXSRQDQHQWHU
SULVHEHDQ¶VKRPHLQWHUIDFH'RQ¶WZRUU\LI\RXKDYHQ¶W
XVHG(-%VEHIRUHDQGGRQ¶WNQRZZKDWWKDWODVWVHQWHQFH
PHDQV²\RXGRQ¶WQHHG(-%NQRZOHGJHIRUWKLVH[DP
7KHHMEUHIW\SH!GHVFULEHVZKHWKHUWKLVLVDQ(QWLW\RU6HV
VLRQEHDQ7KRVHWZRHOHPHQWVWKHORRNXSQDPHDQGWKH
EHDQW\SHGRQ¶WGHSHQGRQZKHWKHUWKHEHDQLVORFDOUXQ
QLQJLQWKHVDPH-90DVWKHZHEFRPSRQHQWRUUHPRWH
SRWHQWLDOO\UXQQLQJLQDGLIIHUHQW-90
%XWORRNDWWKHRWKHUHOHPHQWVVWDUWLQJZLWKWKHRXWHUWDJV
HMEORFDOUHI!DQGHMEUHI!<RXPLJKWEHWHPSWHGWRWKLQN
WKDWLW¶V
HME
ORFDO
UHI!
HME
UHPRWH
UHI!
%XW12)RUUHPRWHEHDQVLW¶VMXVW
HMEUHI!
,QRWKHUZRUGVWKHORFDOUHIHUHQFHVD\VLW¶VORFDOEXWWKH
UHPRWHUHIHUHQFHGRHV127LQFOXGHWKHZRUG³UHPRWH´LQLWV
WDJHOHPHQWQDPH:K\"%HFDXVHDWWKHWLPHHMEUHI!ZDV
¿UVWGH¿QHGWKHUHZDVQRVXFKWKLQJDV³ORFDO´(-%V6LQFH
$//HQWHUSULVHEHDQVZHUH³UHPRWH´WKHUHZDVQRQHHGWR
GLIIHUHQWLDWHEHWZHHQORFDODQGUHPRWHVRQRQHHGWRSXW
³UHPRWH´LQWKHQDPHRIWKHWDJ
7KLVDOVRH[SODLQVWKH27+(5WDJQDPLQJLQFRQVLVWHQF\²
WKHQDPHRIWKHWDJIRUWKHEHDQ¶VKRPHLQWHUIDFH$ORFDO
EHDQXVHV
ORFDO
KRPH!
EXWDUHPRWHEHDQGRHV127XVH
UHPRWH
KRPH!
)RUUHPRWHEHDQVLW¶VMXVW
KRPH!
7KH/2&$/DQG5(027(
WDJVDUHLQFRQVLVWHQW
yes
Wrong!!
Right! ThereÕs no ÒremoteÓ in the tag.
Yes
Wrong!!
PR
UHPRW
UHPRW
PR
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
5MUWZQbQVO\PM26,1$MV^MV\Za&,,\IO
)FYOUREFAMILIARWITH%*"ANDOR*.$)THISWILLMAKESENSE)FYOURE
NOTITDOESNTREALLYMATTERFORTHEEXAMASLONGASYOUMEMORIZETHE
TAG4HEDETAILSSURROUNDING*.$)ENVIRONMENTENTRIESARECOVEREDIN
%*"*%%BOOKSLIKETHELOVELY(EAD&IRST%*"
4HINKOFANENVIRONMENTENTRYASBEINGSOMETHINGLIKEADEPLOYTIME
CONSTANTTHATYOURAPPCANUSEMUCHLIKESERVLETANDCONTEXTINIT
PARAMETERS)NOTHERWORDSAWAYFORTHEDEPLOYERTOPASSVALUESINTO
THESERVLETORINTHISCASEAN%*"ASWELLIFTHISISDEPLOYEDASPARTOFAN
ENTERPRISEAPPLICATIONINAFULLY*%%COMPLIANTSERVER
!TDEPLOYTIMETHE#ONTAINERREADSTHE$$ANDMAKESA*.$)ENTRY
AGAINASSUMINGTHISISAFULLY*%%COMPLIANTAPPANDNOTJUSTASERVER
WITHONLYAWEB#ONTAINERUSINGTHENAMEANDVALUEYOUSUPPLYINTHIS
$$TAG!TRUNTIMEACOMPONENTINTHEAPPLICATIONCANLOOKUPTHE
VALUEIN*.$)USINGTHENAMELISTEDINTHE$$9OUPROBABLYWONTCARE
ABOUTENVENTRYUNLESSYOUREALSODEVELOPINGWITH%*"SSOTHEONLY
REASONYOUNEEDTOMEMORIZETHISISFORTHEEXAM
HQYHQWU\!
HQYHQWU\QDPH!UDWHVGLVFRXQW5DWHHQYHQWU\QDPH!
HQYHQWU\
W\SH!MDYDODQJ,QWHJHUHQYHQWU\W\SH!
HQYHQWU\
YDOXH!HQYHQWU\YDOXH!
HQYHQWU\!
'HFODULQJDQDSS·V-1',HQYLURQPHQWHQWU\
The lookup name youÕll use in code.
This can be any type that takes
a single String as a constructor
parameter (or a single Character if
itÕs java.lang.Character).
This will be passed in as a String (or a
single Character if the <env-entry-type>
is java.lang.Character).
Note: you can also include an
optional <description>, which is a
REALLY REALLY good idea.
:KHQ\RXVHHDQHQYHQWU\YDOXH!WKDW¶VDQLQWHJHU
YDOXHOLNHWKHH[DPSOHDERYH\RXPLJKWWKLQNWKDWWKH
HQYHQWU\W\SH!FDQEHDSULPLWLYH%XWWKDWZRXOGEH
ZURQJ
<RXDOVRPLJKWEHWHPSWHGWRWKLQNWKDW\RXFDQKDYH
RQO\6WULQJVDQGZUDSSHUVEXWWKDW¶VZURQJWRR²\RX
FDQXVHDQ\W\SHWKDWWDNHVDVLQJOH6WULQJLQLWV
FRQVWUXFWRURUDVLQJOH&KDUDFWHUIRUD&KDUDFWHUW\SH
7KHHQYHQWU\W\SH!PXVW
127EHDSULPLWLYH
FRQ¿JXULQJWKHHQYHQWU\!
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
5MUWZQbQVO\PM$UQUMUIXXQVO&,,\IO
9OUCANCONlGUREAMAPPINGBETWEENANEXTENSIONANDAMIMETYPEINTHE
$$4HISWILLPROBABLYBETHEEASIESTTAGTOREMEMBERBECAUSEITJUSTMAKES
SENSEYOUMAPBETWEENANEXTENSIONANDAMIMETYPEANDGUESSWHAT)N
ARAREMOMENTOFSIMPLICITYANDCLARITYTHEYNAMEDTHETAGSUBELEMENTS
hEXTENSIONvANDhMIMETYPEv4HATMEANSYOUHAVETOREMEMBERONLYONE
THINGTHATTHETAGELEMENTSARENAMEDFOREXACTLYWHATTHEYARE
5NLESSYOUSTARTTHINKINGOFITAShlLETYPEvANDhCONTENTTYPEv"UTNOYOU
WONTDOTHAT9OULLMEMORIZEITJUSTLIKETHIS
PLPHPDSSLQJ!
H[WHQVLRQ!PSJH[WHQVLRQ!
PLPHW\SH!YLGHRPSHJPLPHW\SH!
PLPHPDSSLQJ!
'HFODULQJDPLPHPDSSLQJ!
,W¶VMXVWWKHFKDUDFWHUVWKDWPDNH
XSWKHH[WHQVLRQQRWWKH³´WKDW
VHSDUDWHVWKH¿OHQDPHIURPWKH
H[WHQVLRQ
'RQ·WLQFOXGH
WKH´µLQWKH
H[WHQVLRQ
%XUQLWLQ²H[WHQVLRQ!DQGPLPHW\SH!
H[WHQVLRQ!DQGPLPHW\SH!
H[WHQVLRQ!DQGPLPHW\SH!
H[WHQVLRQ!DQGPLPHW\SH!
H[WHQVLRQ!DQGPLPHW\SH!
,W·VQRWÀOHW\SH!DQG
FRQWHQWW\SH!
Do NOT include the dot Ò.Ó!
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
H[HUFLVHRQGHSOR\PHQW
5HVRXUFHW\SH
'HSOR\PHQW'HVFULSWRU
ZHE[PO
7DJ)LOHV
WDJRUWDJ[
'HSOR\PHQWORFDWLRQ
+70/DQG-63V
7KDW\RXZDQWWREH
GLUHFWO\DFFHVVLEOH
7/'V
WOG
6HUYOHWFODVVHV
7DJ+DQGOHUFODVVHV
-$5ILOHV
Directly inside WEB-INF (which is directly inside the root of
the web app).
+70/DQG-63V
7KDW\RXZDQWWR´KLGHµ
IURPGLUHFWFOLHQWDFFHVV
6KDUSHQ \RXU SHQFLO
:KHUHWKLQJVJR
)LOOLQWKLVWDEOHZLWKH[SOLFLWQRWHVRQZKHUHLQWKHZHEDSS
WKHJLYHQUHVRXUFHPXVWEHSODFHG:HGLGWKHILUVWRQHIRU
\RX7XUQWKHSDJHIRUWKHDQVZHUV
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
!
!HME&XVWRPHU !
HMEUHIW\SH!(QWLW\HMEUHIW\SH!
!FRPZLFNHGO\VPDUW&XVWRPHU+RPH !
ORFDO!FRPZLFNHGO\VPDUW&XVWRPHUORFDO!
!
HMEUHI!
!HME/RFDO&XVWRPHU !
HMEUHIW\SH!(QWLW\HMEUHIW\SH!
!FRPZLFNHGO\VPDUW&XVWRPHU+RPH !
!FRPZLFNHGO\VPDUW&XVWRPHU !
HMEUHI!
HUURUSDJH!
!MDYDLR,2([FHSWLRQ !
!P\HUURUMVS !
HUURUSDJH!
HQYHQWU\!
!UDWHVGLVFRXQW5DWH !
!MDYDODQJ,QWHJHU !
HQYHQWU\
YDOXH!HQYHQWU\YDOXH!
HQYHQWU\!
!
ZHOFRPHILOH!LQGH[KWPOZHOFRPHILOH!
!
6KDUSHQ \RXU SHQFLO
0HPRUL]LQJ''WDJV
,I\RX·UH127SODQQLQJRQWDNLQJWKH
H[DPGRQ·WZRUU\DERXWJHWWLQJDOO
RIWKHVHULJKWDOWKRXJKWKHERWWRP
WZRHOHPHQWVDUHLPSRUWDQWWR
DOPRVWHYHU\RQH
,I\RX$5(JRLQJWRWDNHWKHH[DP
\RXVKRXOGVSHQGVRPHWLPH
PHPRUL]LQJWKHVH
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
H[HUFLVHRQGHSOR\PHQW
5HVRXUFHW\SH
'HSOR\PHQW'HVFULSWRU
ZHE[PO
7DJ)LOHV
WDJRUWDJ[
'HSOR\PHQWORFDWLRQ
+70/DQG-63V
7KDW\RXZDQWWREH
GLUHFWO\DFFHVVLEOH
7/'V
WOG
6HUYOHWFODVVHV
7DJ+DQGOHUFODVVHV
-$5ILOHV
Directly inside WEB-INF (which is directly inside the root of
the web app).
+70/DQG-63V
7KDW\RXZDQWWR´KLGHµ
IURPGLUHFWFOLHQWDFFHVV
If NOT deployed inside a JAR, Tag Files must be inside WEB-INF/tags, or
a subdirectory of WEB-INF/tags. If deployed in a JAR, Tag Files must
be in META-INF/tags, or a subdirectory of META-INF/tags. Note: Tag
Files deployed in a JAR must have a TLD in the JAR.
Client-accessible HTML and JSPs can be anywhere under the root of the web app
or any of its subdirectories, EXCEPT they cannot be under WEB-INF (including
subdirectories). In a WAR Þle, they canÕt be under META-INF (including subdirectories).
Pages under WEB-INF (or META-INF in a WAR Þle) cannot be directly
accessed by clients.
If NOT inside a JAR, TLD Þles must be somewhere under WEB-INF or
a subdirectory of WEB-INF. If deployed in a JAR, TLD Þles must be
somewhere under META-INF, or a subdirectory of META-INF.
Servlet classes must be in a directory structure matching the package
structure, placed directory under WEB-INF/classes (for example, class com.
example.Ring would be inside WEB-INF/classes/com/example), or in the
appropriate package directories within a JAR inside WEB-INF/lib).
Actually ALL classes used by the web-app (unless theyÕre part of the class
libraries on the classpath) must follow the same rules as servlet classesÑinside
WEB-INF/classes, in a directory structure matching the package (or in the
appropriate package directories within a JAR inside WEB-INF/lib).
JAR Þles must be inside the WEB-INF/lib directory.
6KDUSHQ \RXU SHQFLO
:KHUHWKLQJVJR
)LOOLQWKLVWDEOHZLWKH[SOLFLWQRWHVRQZKHUHLQWKHZHEDSS
WKHUHVRXUFHPXVWEHSODFHG:HGLGWKHILUVWRQHIRU\RX
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
ejb-local-ref !
ejb-ref-name !HME&XVWRPHU/ejb-ref-name !
HMEUHIW\SH!(QWLW\HMEUHIW\SH!
local-home !FRPZLFNHGO\VPDUW&XVWRPHU+RPH/local-home !
ORFDO!FRPZLFNHGO\VPDUW&XVWRPHUORFDO!
/ejb-local-ref !
HMEUHI!
ejb-ref-name !HME/RFDO&XVWRPHU/ejb-ref-name !
HMEUHIW\SH!(QWLW\HMEUHIW\SH!
home !FRPZLFNHGO\VPDUW&XVWRPHU+RPH/home !
remote !FRPZLFNHGO\VPDUW&XVWRPHU/remote !
HMEUHI!
HUURUSDJH!
exception-type !MDYDLR,2([FHSWLRQ/exception-type !
location !P\HUURUMVS/location !
HUURUSDJH!
HQYHQWU\!
env-entry-name !UDWHVGLVFRXQW5DWH/env-entry-name !
env-entry-type !MDYDODQJ,QWHJHU/env-entry-type !
HQYHQWU\
YDOXH!HQYHQWU\YDOXH!
HQYHQWU\!
welcome-file-list !
ZHOFRPHILOH!LQGH[KWPOZHOFRPHILOH!
/welcome-file-list !
6KDUSHQ \RXU SHQFLO
0HPRUL]LQJ''WDJV
$16:(56
,I\RXDUHJRLQJWRWDNHWKHH[DP
\RXVKRXOGVSHQGVRPHWLPH
PHPRUL]LQJ$//RIWKHVHSOXVDQ\
RIWKHRWKHUVIURPIURPWKLVFKDSWHU
DQGWKHVHFXULW\UHODWHGWDJV\RX·OO
VHHLQWKHQH[WFKDSWHU
A reference to a bean that
has a ÒlocalÓ interface.
A reference to a bean that
has a ÒremoteÓ interface.
An environment entry is
a way to get deploy-time
constants into a J2EE
application.
Tells the Container which page
to show when the speciÞed
<exception-type> occurs.
Tells the Container which page
to look for when a request comes
in that doesnÕt match a speciÞc
resource. There can be more than
one <welcome-Þle> speciÞed in
the <welcome-Þle-list>.
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
7HERECANLQLWSDUDP!ELEMENTSAPPEARINTHE$$
#HOOSEALLTHATAPPLY
R!!SCHILDELEMENTSOFVHUYOHW!
R"!SDIRECTDESCENDANTSOFZHEDSSOLFDWLRQ!ELEMENTS
R#*USTAFTERTHE$OCUMENT4YPE$ECLARATION
R$)NSIDEOFFRQWH[WSDUDP!ELEMENTSWHENYOUWANTTO
DECLAREACONTEXTINITIALIZATIONPARAMETER
0RFN([DP&KDSWHU
7HEREDOYOUSTORE4AG,IBRARY$ESCRIPTORS4,$SINAWEBAPPLICATION
#HOOSEALLTHATAPPLY
R!/NLYIN:(%,1)OLE
R"/NLYIN:(%,1)FODVVHV
R#)NTHE0(7$,1)DIRECTORYOFA*!2lLEINSIDE
:(%,1)OLE
R$!TTHEAPPLICATIONSTOPLEVELDIRECTORY
R%)N:(%,1)ORASUBDIRECTORYTHEREOF
7HICHSTATEMENTSABOUT7!2lLESARETRUE#HOOSEALLTHATAPPLY
R!7!2STANDSFOR7EB!PPLICATION2ESOURCESlLE
R"!VALID7!2lLEMUSTCONTAINADEPLOYMENTDESCRIPTOR
R#3EVERAL7!2lLESCANCOMPOSEAWEBAPPLICATION
R$!7!2lLECANNOTCONTAINEMBEDDED*!2lLES
PRFNH[DP
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
4HEFOLLOWINGSERVLETISDECLAREDINTHE$$
VHUYOHW!
VHUYOHWQDPH!0\6HUYOHWVHUYOHWQDPH!
VHUYOHWFODVV!FRPP\RUJ6HUYOHW&ODVVVHUYOHWFODVV!
VHUYOHW!
7HERECANYOUSTORETHESERVLETCLASSINTHEWEBAPPLICATION#HOOSEALLTHAT
APPLY
R!)N0(7$,1)OFA*!2lLE
R")NTHEPACKAGERELATEDDIRECTORYTREEBEGININGATTHETOPLEVELOFTHE
APPLICATIONDIRECTORY
R#)N:(%,1)FODVVHVORINA*!2lLEIN:(%,1)OLE
R$)N:(%,1)OLEOUTSIDEOFA*!2lLE
7HATISTHEPURPOSEOFTHEDEPLOYMENTDESCRIPTOR$$#HOOSEALLTHAT
APPLY
R!4OALLOWCODEGENERATIONTOOLSTODYNAMICALLYCREATESERVLETSFROMAN
8-,lLE
R"4OCONVEYTHEWEBAPPLICATIONCONlGURATIONINFORMATIONFROM
DEVELOPERSTOAPPLICATIONASSEMBLERSANDDEPLOYERS
R#4OCONlGUREVENDORSPECIlCASPECTSOFTHEAPPLICATION
R$4OCONlGUREONLYDATABASEAND%NTERPRISE*AVA"EANACCESSFROMTHE
WEBAPPLICATION
7HERESHOULDZHE[POBESTOREDINA7!2lLE#HOOSEALLTHATAPPLY
R!)N:(%,1)FODVVHV
R")N:(%,1)OLE
R#)N:(%,1)
R$)N0(7$,1)
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
'IVEN
#SDJHLPSRUW ´MDYDXWLO´!
MVSLPSRUWLPSRUW ´MDYDXWLO´!
MVSGLUHFWLYHSDJHLPSRUW ´MDYDXWLO´!
MVSSDJHLPSRUW ´MDYDXWLO´!
!SSUMETHEPRElXhJSPvHASBEENMAPPEDTOTHENAMESPACE
KWWSMDYDVXQFRP-633DJH
7HICHARETRUE#HOOSEALLTHATAPPLY
R!,INESANDAREEQUIVALENTINANYTYPEOF*30PAGE
R",INEISNOTVALIDINA*30DOCUMENT8-,BASEDDOCUMENT
R#,INEWILLPROPERLYIMPORTTHEMDYDXWLOPACKAGE
R$,INEWILLPROPERLYIMPORTTHEMDYDXWLOPACKAGE
R%,INEWILLPROPERLYIMPORTTHEMDYDXWLOPACKAGE
7HICHSTATEMENTSABOUTLQLWSDUDP!$$ELEMENTSARETRUE
#HOOSEALLTHATAPPLY
R!4HEYAREUSEDTODECLAREINITIALIZATIONPARAMETERSFORA
SPECIlCSERVLET
R"4HEYAREUSEDTODECLAREINITIALIZATIONPARAMETERSFORAN
ENTIREWEBAPP
R#4HEMETHODTHATRETRIEVESTHESEPARAMETERSRETURNSAN
OBJECT
R$4HEMETHODTHATRETRIEVESTHESEPARAMETERSTAKESA3TRING
7HICHARE$$ELEMENTSTHATPROVIDE*.$)ACCESSTO*%%COMPONENTS
#HOOSEALLTHATAPPLY
R!HMEUHI!
R"HQWLW\UHI!
R#UHVRXUFHUHI!
R$VHVVLRQUHI!
R%PHVVDJHUHI!
PRFNH[DP
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
4HEFOLLOWINGSERVLETISREGISTEREDINTHE$$
VHUYOHW!
VHUYOHWQDPH!DFWLRQVHUYOHWQDPH!
VHUYOHWFODVV!FRPP\RUJ$FWLRQ&ODVVVHUYOHWFODVV!
VHUYOHW!
#HOOSETHECORRECTMAPPINGSFORTHISSERVLET#HOOSEALLTHATAPPLY
R!VHUYOHWPDSSLQJ!
VHUYOHWQDPH!DFWLRQVHUYOHWQDPH!
XUOSDWWHUQ!GRXUOSDWWHUQ!
VHUYOHWPDSSLQJ!
R"VHUYOHWPDSSLQJ!
VHUYOHWQDPH!FRPP\RUJ$FWLRQ&ODVVVHUYOHWQDPH!
XUOSDWWHUQ!GRXUOSDWWHUQ!
VHUYOHWPDSSLQJ!
R#VHUYOHWPDSSLQJ!
VHUYOHWQDPH!DFWLRQVHUYOHWQDPH!
XUOSDWWHUQ!FRQWUROOHUXUOSDWWHUQ!
VHUYOHWPDSSLQJ!
R$VHUYOHWPDSSLQJ!
XUOSDWWHUQ!GRXUOSDWWHUQ!
VHUYOHWPDSSLQJ!
R%VHUYOHWPDSSLQJ!
VHUYOHWQDPH!DFWLRQVHUYOHWQDPH!
VHUYOHWPDSSLQJ!
&ORWHICHTYPEOFWEBAPPCOMPONENTSCANDEPENDENCIESBEDElNED
#HOOSEALLTHATAPPLY
R!*30lLES
R"7!2lLES
R#CLASSES
R$LIBRARIES
R%MANIFESTlLES
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
7HICHDEPLOYMENTDESCRIPTORELEMENTSMAYAPPEARBEFORETHEZHEDSS!
ELEMENT#HOOSEALLTHATAPPLY
R!OLVWHQHU!
R"FRQWH[WSDUDP!
R#VHUYOHW!
R$.O8-,ELEMENTSMAYAPPEARBEFORETHEZHEDSS!ELEMENT
7HICHSTATEMENTSCONCERNINGTHECONTAINERCLASSLOADERARETRUE
#HOOSEALLTHATAPPLY
R!7EBAPPLICATIONSSHOULD./4ATTEMPTTOOVERRIDECONTAINER
IMPLEMENTATIONCLASSES
R"!WEBAPPLICATIONMUSTNOTATTEMPTTOLOADRESOURCESFROM
WITHINTHE7!2lLEUSINGTHE*3%SEMANTICSOFGET2ESOURCE
R#!WEBAPPLICATIONMAYOVERRIDEANY*%%CLASSESINTHEJAVAX
NAMESPACE
R$!WEBDEVELOPERMAYOVERRIDE*%%PLATFORMCLASSESPROVIDED
THEYARECONTAINEDINALIBRARY*!2WITHINA7!2
7HICHAREVALIDDECLARATIONSINA*30$OCUMENT8-,BASEDDOCUMENT
#HOOSEALLTHATAPPLY
R!MVSGHFODUDWLRQ
[POQVMVS ´KWWSMDYDVXQFRP-633DJH´!
LQW[
MVSGHFODUDWLRQ!
R"MVSGHFODUDWLRQ
[POQVMVS ´KWWSMDYDVXQFRP-633DJH´!
LQW[
MVSGHFODUDWLRQ!
R#LQW[ !
R$LQW[!
PRFNH[DP
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
7HERECANLQLWSDUDP!ELEMENTSAPPEARINTHE$$
#HOOSEALLTHATAPPLY
R!!SCHILDELEMENTSOFVHUYOHW!
R"!SDIRECTDESCENDANTSOFZHEDSSOLFDWLRQ!ELEMENTS
R#*USTAFTERTHE$OCUMENT4YPE$ECLARATION
R$)NSIDEOFFRQWH[WSDUDP!ELEMENTSWHENYOUWANTTO
DECLAREACONTEXTINITIALIZATIONPARAMETER
&KDSWHU$QVZHUV
7HEREDOYOUSTORE4AG,IBRARY$ESCRIPTORS4,$SINAWEBAPPLICATION
#HOOSEALLTHATAPPLY
R!/NLYIN:(%,1)OLE
R"/NLYIN:(%,1)FODVVHV
R#)NTHE0(7$,1)DIRECTORYOFA*!2lLEINSIDE
:(%,1)OLE
R$!TTHEAPPLICATIONSTOPLEVELDIRECTORY
R%)N:(%,1)ORASUBDIRECTORYTHEREOF
(JSP spec pg 196)
-The container will not automatically
discover TLDs if they are in
/WEB-INF/classes or /WEB-INF/lib.
(Servlet spec pg 107)
-Option B is incorrect because
web.xml does not contain an
element named <web-application>.
- Option D is incorrect because
<context-param> elements do
not contain <init-param>.
7HICHSTATEMENTSABOUT7!2lLESARETRUE#HOOSEALLTHATAPPLY
R!7!2STANDSFOR7EB!PPLICATION2ESOURCESlLE
R"!VALID7!2lLEMUSTCONTAINADEPLOYMENTDESCRIPTOR
R#3EVERAL7!2lLESCANCOMPOSEAWEBAPPLICATION
R$!7!2lLECANNOTCONTAINEMBEDDED*!2lLES
(servlet spec 9.5 & 9.6)
-WAR stands for Web ARchive,
and portions of a web application
cannot be contained in a WAR
Þle; only an entire application can
reside within a WAR Þle.
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
4HEFOLLOWINGSERVLETISDECLAREDINTHE$$
VHUYOHW!
VHUYOHWQDPH!0\6HUYOHWVHUYOHWQDPH!
VHUYOHWFODVV!FRPP\RUJ6HUYOHW&ODVVVHUYOHWFODVV!
VHUYOHW!
7HERECANYOUSTORETHESERVLETCLASSINTHEWEBAPPLICATION#HOOSEALLTHAT
APPLY
R!)N0(7$,1)OFA*!2lLE
R")NTHEPACKAGERELATEDDIRECTORYTREEBEGININGATTHETOPLEVELOFTHE
APPLICATIONDIRECTORY
R#)N:(%,1)FODVVHVORINA*!2lLEIN:(%,1)OLE
R$)N:(%,1)OLEOUTSIDEOFA*!2lLE
(Servlet spec p 70)
-Option D is not correct because /WEB-INF/lib
is designed as the container for JAR Þles.
7HATISTHEPURPOSEOFTHEDEPLOYMENTDESCRIPTOR$$#HOOSEALLTHAT
APPLY
R!4OALLOWCODEGENERATIONTOOLSTODYNAMICALLYCREATESERVLETSFROMAN
8-,lLE
R"4OCONVEYTHEWEBAPPLICATIONCONlGURATIONINFORMATIONFROM
DEVELOPERSTOAPPLICATIONASSEMBLERSANDDEPLOYERS
R#4OCONlGUREVENDORSPECIlCASPECTSOFTHEAPPLICATION
R$4OCONlGUREONLYDATABASEAND%NTERPRISE*AVA"EANACCESSFROMTHE
WEBAPPLICATION
(Servlet spec p 103)
-Option D is inaccurate
because these concerns
are just a subset of the
DDÕs purpose.
7HERESHOULDZHE[POBESTOREDINA7!2lLE#HOOSEALLTHATAPPLY
R!)N:(%,1)FODVVHV
R")N:(%,1)OLE
R#)N:(%,1)
R$)N0(7$,1)
(Servlet spec p 70)
-web.xml should be stored in /WEB-INF
regardless of whether the deployment
involves a WAR or an exploded directory
structure.
PRFNDQVZHUV
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
7HICHSTATEMENTSABOUTLQLWSDUDP!$$ELEMENTSARETRUE
#HOOSEALLTHATAPPLY
R!4HEYAREUSEDTODECLAREINITIALIZATIONPARAMETERSFORA
SPECIlCSERVLET
R"4HEYAREUSEDTODECLAREINITIALIZATIONPARAMETERSFORAN
ENTIREWEBAPP
R#4HEMETHODTHATRETRIEVESTHESEPARAMETERSRETURNSAN
OBJECT
R$4HEMETHODTHATRETRIEVESTHESEPARAMETERSTAKESA3TRING
(servlet spec SRV.B & API)
-Initialization parameters can
have web app scope or servlet
scope. Those with servlet
scope are named <init-param>
in the DD, and take and
return a String. Those with
web app scope are named
<context-param> in the DD
and also take and return a
String.
7HICHARE$$ELEMENTSTHATPROVIDE*.$)ACCESSTO*%%COMPONENTS
#HOOSEALLTHATAPPLY
R!HMEUHI!
R"HQWLW\UHI!
R#UHVRXUFHUHI!
R$VHVVLRQUHI!
R%PHVVDJHUHI!
(servlet spec 9.11)
-In addition, <ejb-local-ref> also provides
the web app creator with a JNDI reference
to J2EE components.
'IVEN
#SDJHLPSRUW ´MDYDXWLO´!
MVSLPSRUWLPSRUW ´MDYDXWLO´!
MVSGLUHFWLYHSDJHLPSRUW ´MDYDXWLO´!
MVSSDJHLPSRUW ´MDYDXWLO´!
!SSUMETHEPRElXhJSPvHASBEENMAPPEDTOTHENAMESPACE
KWWSMDYDVXQFRP-633DJH
7HICHARETRUE#HOOSEALLTHATAPPLY
R!,INESANDAREEQUIVALENTINANYTYPEOF*30PAGE
R",INEISNOTVALIDINA*30DOCUMENT8-,BASEDDOCUMENT
R#,INEWILLPROPERLYIMPORTTHEMDYDXWLOPACKAGE
R$,INEWILLPROPERLYIMPORTTHEMDYDXWLOPACKAGE
R%,INEWILLPROPERLYIMPORTTHEMDYDXWLOPACKAGE
(JSP v2.0 pg. 1-139)
-Option A is incorrect because line 10
would be invalid in a JSP Document
(XML-based document).
-Options C and E are invalid as
they are not valid elements in the
namespace.
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
4HEFOLLOWINGSERVLETISREGISTEREDINTHE$$
VHUYOHW!
VHUYOHWQDPH!DFWLRQVHUYOHWQDPH!
VHUYOHWFODVV!FRPP\RUJ$FWLRQ&ODVVVHUYOHWFODVV!
VHUYOHW!
#HOOSETHECORRECTMAPPINGSFORTHISSERVLET#HOOSEALLTHATAPPLY
R!VHUYOHWPDSSLQJ!
VHUYOHWQDPH!DFWLRQVHUYOHWQDPH!
XUOSDWWHUQ!GRXUOSDWWHUQ!
VHUYOHWPDSSLQJ!
R"VHUYOHWPDSSLQJ!
VHUYOHWQDPH!FRPP\RUJ$FWLRQ&ODVVVHUYOHWQDPH!
XUOSDWWHUQ!GRXUOSDWWHUQ!
VHUYOHWPDSSLQJ!
R#VHUYOHWPDSSLQJ!
VHUYOHWQDPH!DFWLRQVHUYOHWQDPH!
XUOSDWWHUQ!FRQWUROOHUXUOSDWWHUQ!
VHUYOHWPDSSLQJ!
R$VHUYOHWPDSSLQJ!
XUOSDWWHUQ!GRXUOSDWWHUQ!
VHUYOHWPDSSLQJ!
R%VHUYOHWPDSSLQJ!
VHUYOHWQDPH!DFWLRQVHUYOHWQDPH!
VHUYOHWPDSSLQJ!
-Option B is incorrect because it
confuses the servlet name with the
servlet class.
&ORWHICHTYPEOFWEBAPPCOMPONENTSCANDEPENDENCIESBEDElNED
#HOOSEALLTHATAPPLY
R!*30lLES
R"7!2lLES
R#CLASSES
R$LIBRARIES
R%MANIFESTlLES
(servlet spec 9.7.1)
- Libraries dependencies can be deÞned in
the /META-INF/MANIFEST.MF Þle.
-Option D is incorrect because it
omits the <servlet-name> child
element of <servlet-mapping>.
(servlet spec pg 86)
PRFNDQVZHUV
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSGHSOR\PHQW
\RXDUHKHUH
7HICHDEPLOYMENTDESCRIPTORELEMENTSMAYAPPEARBEFORETHEZHEDSS!
ELEMENT#HOOSEALLTHATAPPLY
R!OLVWHQHU!
R"FRQWH[WSDUDP!
R#VHUYOHW!
R$.O8-,ELEMENTSMAYAPPEARBEFORETHEZHEDSS!ELEMENT
(Servlet spec, p 107)
-The <web-app> element is the root element
of the web application deployment descriptor.
7HICHSTATEMENTSCONCERNINGTHECONTAINERCLASSLOADERARETRUE
#HOOSEALLTHATAPPLY
R!7EBAPPLICATIONSSHOULD./4ATTEMPTTOOVERRIDECONTAINER
IMPLEMENTATIONCLASSES
R"!WEBAPPLICATIONMUSTNOTATTEMPTTOLOADRESOURCESFROM
WITHINTHE7!2lLEUSINGTHE*3%SEMANTICSOFGET2ESOURCE
R#!WEBAPPLICATIONMAYOVERRIDEANY*%%CLASSESINTHEJAVAX
NAMESPACE
R$!WEBDEVELOPERMAYOVERRIDE*%%PLATFORMCLASSESPROVIDED
THEYARECONTAINEDINALIBRARY*!2WITHINA7!2
(Servlet spec, 9.7.2)
7HICHAREVALIDDECLARATIONSINA*30$OCUMENT8-,BASEDDOCUMENT
#HOOSEALLTHATAPPLY
R!MVSGHFODUDWLRQ
[POQVMVS ´KWWSMDYDVXQFRP-633DJH´!
LQW[
MVSGHFODUDWLRQ!
R"MVSGHFODUDWLRQ
[POQVMVS ´KWWSMDYDVXQFRP-633DJH´!
LQW[
MVSGHFODUDWLRQ!
R#LQW[ !
R$LQW[!
(JSP v2.0 pg. 1-139)
-Options C and D are incorrect
because only the <jsp:declaration>
syntax is valid in JSP Documents.
-Option B is incorrect because the
webapp may use the getResource
method from the webappÕs class
loader to access any WAR Þle.
-Options C & D are incorrect
because the webapp must NOT
override any class in the java.*
or javax.* namespaces.
Chapter 11. Deploying your web app
Chapter 11. Deploying your web app
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID:
Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
WKLVLVDQHZFKDSWHU
<RXUZHEDSSLVLQ
GDQJHU
7URXEOHOXUNVLQHYHU\FRUQHURIWKH
QHWZRUNDVFUDFNHUVVFDPPHUVDQGFULPLQDOVWU\WREUHDNLQWR\RXUV\VWHP
WRVWHDOWDNHDGYDQWDJHRUMXVWKDYHDOLWWOHIXQZLWK\RXUVLWH<RXGRQ¶WZDQW
WKH%DG*X\VOLVWHQLQJLQWR\RXURQOLQHVWRUHWUDQVDFWLRQVSLFNLQJRIIFUHGLW
FDUGQXPEHUV<RXGRQ¶WZDQWWKH%DG*X\VFRQYLQFLQJ\RXUVHUYHUWKDW
WKH\¶UHDFWXDOO\WKH6SHFLDO&XVWRPHUV:KR*HW%LJ'LVFRXQWV$QG\RXGRQ¶W
ZDQWDQ\RQHJRRG25EDGORRNLQJDWVHQVLWLYHHPSOR\HHGDWD'RHV-LPLQ
PDUNHWLQJUHDOO\QHHGWRNQRZWKDW/LVDLQHQJLQHHULQJPDNHVWKUHHWLPHVDV
PXFKDVKHGRHV"$QGGR\RXUHDOO\ZDQW-LPWRWDNHPDWWHUVLQWRKLVRZQKDQGV
DQGORJLQXQDXWKRUL]HGWRWKH8SGDWH3D\UROOVHUYOHW"
.HHSLWVHFUHWNHHSLWVDIH
ZHEDSSVHFXULW\
7KH\·UHRXWWKHUH7KH
%DG*X\VWKH\·UHHYHU\ZKHUH
,
PXVW
OHDUQDERXW$XWKHQWLFDWLRQ
DQG$XWKRUL]DWLRQ,
PXVW
OHDUQWR
WUDQVPLWWKHGDWDVHFXUHO\,,
','<28+($57+$7"
Chapter 12. Keep it secret, keep it safe
Chapter 12. Keep it secret, keep it safe
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher:
O'Reilly
Prepared for Augusto Jaramillo Forcada, Safari ID:
Print Publication Date: 8/1/2004 User number: 729515 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
%DVHGRQWKHVHUYOHWVSHFL¿FDWLRQFRPSDUH
DQGFRQWUDVWWKHIROORZLQJVHFXULW\LVVXHV
DDXWKHQWLFDWLRQEDXWKRUL]DWLRQFGDWD
LQWHJULW\DQGGFRQ¿GHQWLDOLW\
6HUYOHWV-63RYHUYLHZ
RI¿FLDO6XQH[DPREMHFWLYHV
!LLOFTHEOBJECTIVESINTHISSECTIONARECOVERED
COMPLETELYINTHISCHAPTERINCLUDINGSECURITY
RELATED$$ELEMENTSTHATWERE./4COVEREDIN
THEDEPLOYMENTCHAPTER
7ECANTMAKEYOUACOMPLETESECURITYBEING
BUTTHECONTENTINTHISCHAPTERISASTARTAND
ITSEVERYTHINGYOUNEEDFORTHEEXAM
&RYHUDJH1RWHV
,QWKHGHSOR\PHQWGHVFULSWRUGHFODUHWKH
IROORZLQJDVHFXULW\FRQVWUDLQWD:HEUHVRXUFH
WKHWUDQVSRUWJXDUDQWHHWKHORJLQFRQ¿JXUDWLRQ
DQGDVHFXULW\UROH
*LYHQDQDXWKHQWLFDWLRQW\SH%$6,&',*(67
)250DQG&/,(17&(57GHVFULEHLWV
PHFKDQLVP
Chapter 12. Keep it secret, keep it safe
Chapter 12. Keep it secret, keep it safe
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher:
O'Reilly
Prepared for Augusto Jaramillo Forcada, Safari ID:
Print Publication Date: 8/1/2004 User number: 729515 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
Copyright Safari Books Online #729515
ZHEDSSVHFXULW\
\RXDUHKHUH
<PM*IL/]a[IZMM^MZa_PMZM
!SAWEBAPPLICATIONDEVELOPERYOUNEEDTOPROTECTYOURWEBSITE
4HEREARETHREEMAINKINDSOFBADGUYSYOUNEEDTOWATCHOUTFOR
)MPERSONATORS5PGRADERSAND%AVESDROPPERS
6HUYHU
2.)UDQNLH,·PLQ
1RZZKDW"<RXPHDQWKDW·V
DOO,KDYHWRGRWRSUHWHQG
WREH+HLGL3OXP"
6HUYHU
1DXJKW\8SJUDGHU
,·PLQWRR,·PDOUHDG\
D
UHJXODU
PHPEHUEXW
QRZ,ÀJXUHGRXWKRZWRVQHDN
LQWRWKH
3UHPLXP
0HPEHUV
DUHDDQGQRZ,FDQGR
$1<7+,1*
3267%X\6WXIIMVS
KWPO!
(QWHU&UHGLW&DUG
LQSXWW\SH WH[WQDPH µFF1XPµ!
KWPO!
KWPO!
(QWHU&UHGLW&DUG
LQSXWW\SH WH[WQDPH µFF1XPµ!
KWPO!
3267%X\:LWK'LVFRXQWMVS
(YLO,PSHUVRQDWRU
Chapter 12. Keep it secret, keep it safe
Chapter 12. Keep it secret, keep it safe
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher:
O'Reilly
Prepared for Augusto Jaramillo Forcada, Safari ID:
Print Publication Date: 8/1/2004 User number: 729515 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
6HUYHUIRU
*RRG*X\VFRP
/RRN'DGG\:H
KDFNHGWKDWODG\·V
FUHGLWFDUGQXPEHU
(YLO(DYHVGURSSHU
,QQRFHQW8VHU
)VLQ\¼[VW\R][\\PM;-:>-:\PI\OM\[P]Z\
%AVESDROPPERSCANBETHEWORST.OTONLYARETHEYTRYINGTOSCAMYOUR
WEBAPPBUTTHEYCANBURNSOMEOFYOURGOODCLIENTSTOO!DOUBLE
HIT)FANEAVESDROPPERISSUCCESSFULHELLSWIPEYOURCLIENTSCREDITCARD
INFORMATIONANDCHARGEUPASTORM
3267&KHFN2XWMVS
>FUHGLWFDUGLQIRUPDWLRQ@
HYLOHDYHVGURSSHUV
Chapter 12. Keep it secret, keep it safe
Chapter 12. Keep it secret, keep it safe
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher:
O'Reilly
Prepared for Augusto Jaramillo Forcada, Safari ID:
Print Publication Date: 8/1/2004 User number: 729515 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSVHFXULW\
\RXDUHKHUH
<PM*QOQV[MZ^TM\[MK]ZQ\a
3ERVLETSECURITYHELPSYOUTHEWEBAPPDEVELOPER
FOIL)MPERSONATORS5PGRADERSAND%AVESDROPPERS
!SFARASTHESERVLETSPECIlCATIONISCONCERNEDAND
HENCETHEEXAMSERVLETSECURITYBOILSDOWNTO
FOURMAINCONCEPTSAUTHENTICATIONAUTHORIZATION
CONlDENTIALITYANDDATAINTEGRITY
6HUYHU
2NEXGG\,JRW\RXU
UHTXHVWEXWKRZGR,NQRZ
\RX
DUHZKR\RXVD\\RXDUH
"
+773UHTXHVW
3267
6HUYHU
6KKK2NZH·YH
JRWWRPDNHVXUHWKDW
QRRQHFDQ
ORRNDWRUPHVV
ZLWK
ZKDW,·PDERXWWR
VHQGRXW
6HUYHU
/RRN'HOEHUWEHIRUH
,FDQVHQG\RXWKLVVSHFLDO
3UHPLXP
ZHESDJH,KDYHWR
PDNHVXUH
\RX·UHDOORZHG
WRVHHLW
$XWKHQWLFDWLRQ
WRIRLO,PSHUVRQDWRUV
$XWKRUL]DWLRQ
WRIRLO8SJUDGHUV
&RQILGHQWLDOLW\'DWD,QWHJULW\
WRIRLO(DYHVGURSSHUV
H[I
JJZ;
VGI#
IGOGG
GG;;GHV
5AGG(G
(QFU\SWHG
UHVSRQVH
+773UHTXHVW
3267
%XVWHG
%XVWHG
%XVWHG
Chapter 12. Keep it secret, keep it safe
Chapter 12. Keep it secret, keep it safe
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher:
O'Reilly
Prepared for Augusto Jaramillo Forcada, Safari ID:
Print Publication Date: 8/1/2004 User number: 729515 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
FKDSWHU
/NEDAY"OBSBOSSCALLED"OBINTOHISOFlCEh)VE
GOTANEXCITINGNEWPROJECTFORYOUvHISBOSS
SAID"OBGROANEDh)KNOW)VEHANDEDYOU
SOMEBADJOBSINTHEPASTBUTTHISONESHOULD
BEREALLYFUN)DLIKEYOUTODESIGNTHESECURITY
FOROURCOMPANYSNEWE#OMMERCEWEBSITEv
h3ECURITYv"OBSAIDhISHARDANDBORINGvh.O
YOUREWRONGvTHEBOSSSAIDh)N*%%SERVLET
SECURITYISSUPPOSEDTOBEPRETTYCOOLv
4HEBOSSCONTINUEDh,ETMEGIVEYOUTHEELEVATOR
PITCHTOGETYOUGOINGTHENWELLGOINTODETAILS
ONCEYOUVEHADACHANCETOTHINKTHISTHROUGHv
h/Kv"OBSIGHEDh,AYITONMEv
h!SYOUKNOWTHISBEERWEBSITEISREALLYHOTRIGHT
NOW7EVEADDEDSEVERALNEWFEATURESANDWERE
GETTINGAGREATRESPONSE3OMEOFOURUSERSARE
HAPPYWITHJUSTTHEFREERECIPESWEOFFERBUTALOT
MOREPEOPLETHANWETHOUGHTAREWILLINGTOPAYFOR
OURRAREHOPSANDOTHERPREMIUMINGREDIENTS/H
ANDOUR&REQUENT"REWERPROGRAMISAHUGEHIT)FA
USERDECIDESHELLBEAREPEATINGREDIENTBUYERHE
CANPAYAONETIMEFEEANDUPGRADETO"REW-ASTER
STATUS!"REW-ASTERGETSPECIALDISCOUNTSAND
EARNS&REQUENT"REWERPOINTSWHICHHECANREDEEM
FORCOOLBREWREWARDSv
"OBCONTINUEDTOLISTENMENTALLYCALCULATINGTHE
CODEHELLHAVETOWRITETOIMPLEMENTALLTHISAND
KISSINGTHATTROPICALVACATIONGOODBYE-EANWHILE
THEBOSSCONTINUED
h"UTNOWWEHAVETOMAKESURETHATWHENONEOF
OURUSERSMAKESAPURCHASENOONECANSWIPEHIS
CREDITCARDINFORMATION/HANOTHERTHINGWED
BETTERMAKESURETHATWHENAMEMBERLOGSINITSNOT
ACTUALLYONEOFHISFRIENDSTRYINGTOSNEAKIN)THINK
WENEEDTOREQUIRETHATMEMBERSHAVEPASSWORDS
FROMNOWONv
)TQ\\TM[MK]ZQ\a[\WZa
:KLFKVHFXULW\FRQFHSWVDUH
PHQWLRQHGLQWKHVWRU\"
5HUHDGWKHVWRU\DQGDQQRWDWHWKHSODFHVZKHUH
WKHERVV·VUHTXLUHPHQWVFDOOIRU
DXWKHQWLFDWLRQ
DXWKRUL]DWLRQ
FRQILGHQWLDOLW\
GDWDLQWHJULW\
<HDK\HDKZHNQRZWKLVLVREYLRXVEXWZH·UHMXVW
ZDUPLQJXSWKHWRSLFEHIRUHLWJHWVGRZQDQGGLUW\
#4X3X98
h)TSALLMAKINGSENSESOFARvSAID"OBh7HENUSERS
PLACEANORDERWITHUSDOWEWANTTOGIVETHEM
SOMESORTOFCONlRMATIONCODEvh'REATIDEAv
SAIDTHEBOSSh/HANDONEMORETHING)FORGOT
YOUBETTERMAKESURETHATONLYOUR&REQUENT"REWERS
GETTHESPECIALDISCOUNTSv
h)THINKTHISISENOUGHvSAIDTHEBOSSh"UTYOU
KNOWTHEWAYTHINGSAREGOINGITPROBABLYWONT
BETOOLONGBEFOREWEOFFERSOMESORTOFPLATINUM
MEMBERSHIPLEVELv
%RE¶VVHFXULW\SURMHFW
Chapter 12. Keep it secret, keep it safe
Chapter 12. Keep it secret, keep it safe
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher:
O'Reilly
Prepared for Augusto Jaramillo Forcada, Safari ID:
Print Publication Date: 8/1/2004 User number: 729515 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
ZHEDSSVHFXULW\
\RXDUHKHUH
AUTHENTICATION - Whenever someone
mentions passwords, theyÕre probably talking
about authentication is this guy who he says
he is? If so, he should know his password!.
AUTHORIZATION - Once we have
established who weÕre talking to, we
want to make sure that theyÕre
allowed to do what they want to do.
CONFIDENTIALITY - It would be a
terrible security breach if a userÕs credit
card number fell into the wrong hands!
CONFIDENTIALITY & DATA INTEGRITY-
At this point the server is returning important
and private information. It would be bad
if the information was seen or altered by an
eavesdropper.
/NEDAY"OBSBOSSCALLED"OBINTOHISOFlCEh)VE
GOTANEXCITINGNEWPROJECTFORYOUvHISBOSS
SAID"OBGROANEDh)KNOW)VEHANDEDYOU
SOMEBADJOBSINTHEPASTBUTTHISONESHOULD
BEREALLYFUN)DLIKEYOUTODESIGNTHESECURITY
FOROURCOMPANYSNEWE#OMMERCEWEBSITEv
h3ECURITYv"OBSAIDhISHARDANDBORINGvh.O
YOUREWRONGvTHEBOSSSAIDh)N*%%SERVLET
SECURITYISSUPPOSEDTOBEPRETTYCOOLv
4HEBOSSCONTINUEDh,ETMEGIVEYOUTHEELEVATOR
PITCHTOGETYOUGOINGTHENWELLGOINTODETAILS
ONCEYOUVEHADACHANCETOTHINKTHISTHROUGHv
h/+v"OBSIGHEDh,AYITONMEv
h!SYOUKNOWTHISBEERWEBSITEISREALLYHOTRIGHT
NOW7EVEADDEDSEVERALNEWFEATURESANDWERE
GETTINGAGREATRESPONSE3OMEOFOURUSERSARE
HAPPYWITHJUSTTHEFREERECIPESWEOFFERBUTALOT
MOREPEOPLETHANWETHOUGHTAREWILLINGTOPAYFOR
OURRAREHOPSANDOTHERPREMIUMINGREDIENTS/H
ANDOUR&REQUENT"REWERPROGRAMISAHUGEHIT)FA
USERDECIDESHELLBEAREPEATINGREDIENTBUYERHE
CANPAYAONETIMEFEEANDUPGRADETO
"REW-ASTER
STATUS!"REW-ASTERGET
SPECIALDISCOUNTS
AND
EARNS&REQUENT"REWER
POINTSWHICHHECANREDEEM
FORCOOLBREWREWARDSv
"OBCONTINUEDTOLISTENMENTALLYCALCULATINGTHE
CODEHELLHAVETOWRITETOIMPLEMENTALLTHISAND
KISSINGTHATTROPICALVACATIONGOODBYE-EANWHILE
THEBOSSCONTINUED
h"UTNOWWEHAVETOMAKESURETHATWHENONEOF
OURUSERSMAKESAPURCHASENOONECANSWIPEHIS
CREDITCARDINFORMATION
/HANOTHERTHINGWED
BETTERMAKESURETHATWHENAMEMBERLOGSINITSNOT
ACTUALLYONEOFHIS
FRIENDSTRYINGTOSNEAKIN)THINK
WENEEDTOREQUIRETHATMEMBERSHAVE
PASSWORDS
FROMNOWONv
)TQ\\TM[MK]ZQ\a[\WZa
h)TSALLMAKINGSENSESOFARvSAID"OBh7HENA
USERPLACESANORDERWITHUSDOWEWANTTOGIVE
THEMSOMESORTOF
CONlRMATIONCODE
vh'REAT
IDEAvSAIDTHEBOSSh/HANDONEMORETHING
)FORGOTYOUBETTERMAKESURETHAT
ONLYOUR
&REQUENT"REWERS
GETTHESPECIALDISCOUNTSv
h)THINKTHISISENOUGHvSAIDTHEBOSSh"UTYOU
KNOWTHEWAYTHINGSAREGOINGITPROBABLYWONT
BETOOLONGBEFOREWEOFFERSOMESORTOFPLATINUM
MEMBERSHIPLEVELv
O
Sh
TTE
G
EN
AY
E
LE
AN
DEEM
MAKE
APU
MAT
Q
THINK
KN
Chapter 12. Keep it secret, keep it safe
Chapter 12. Keep it secret, keep it safe
Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher:
O'Reilly
Prepared for Augusto Jaramillo Forcada, Safari ID:
Print Publication Date: 8/1/2004 User number: 729515 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.