Professional Documents
Culture Documents
4 Tutorial)
Even though Sang Shin is a full-time employee of Sun Microsystems, the contents here are created as his own personal endeavor and thus does not reflect any official stance of Sun Microsystems. Sun Microsystems is not responsible for any inaccuracies in the contents. Acknowledgments
The slides of this presentation are made from !eb Application" section of #$EE %.& tutorial written by Sun Microsystems
A!enda
!eb application, components and !eb container Technologies used in !eb application !eb application development and deployment steps !eb Application Archive '(.!A) file*
(.!A) directory structure !E+-,-. subdirectory !eb application deployment descriptor 'web.0ml file*
JD+"
JA.
JA.
J2%E
'&$
'&$($$)*
J2%E
JD+"
J#D$
J&%
J2%E
Database 5
JD+"
J#D$
J&%
JTA
J#D$
J&%
JTA
Ja-a&ail
Ja-a&ail
!eb components are in the form of either Servlet or #S1 'along with #ava+ean2s and custom tags* !eb components run in a !eb container
Tomcat and )esin are popular web containers All #$EE compliant app servers 'Sun #ava System App Server* provide web containers
!eb components 'Servlets and #S12s* Static resource files such as images 4elper classes 5ibraries 6eployment descriptor 'web.0ml file* A hierarchy of directories and files 'unpacked form* or (.!A) file reflecting the same hierarchy 'packed form*
7
10
Web Application De-elopment and Deplo1ment %teps (usin! hello2 e2ample under J2EE 1.4 tutorial)
11
12
/reate development tree structure !rite either servlet code or #S1 pages along with related helper code /reate build.0ml for Ant-based build 'and other application development life-cycle management* process ,6E 'i.e. -et+eans* handles all these chores
13
)oot directory 'e0ample from hello$ sample code from #$EE %.& tutorial*
build.0ml; Ant build file src; #ava source of servlets and #ava+eans components web; #S1 pages and 4TM5 pages, images
14
4TM5 pages
E0ample; duke.waving.gif
16
6eployment descriptor contains deployment time runtime instructions to the !eb container
17
Either (.!A) file or unpacked form of (.!A) file +uild process is made of
create build directory 'if it is not present* and its subdirectories compile #ava code into build<!E+-,-.<classes directory
copy web.0ml file into build<!E+-,-. directory copy image files into build directory
18
4ello% src web build.0ml build !E+-,-. classes =reetingServlet.class )esponseServlet.class web.0ml duke.waving.gif
19
6eploy the application over deployment platform such as Sun #ava System App Server or Tomcat 7 ways to deploy to Sun #ava System App server
asadmin deploy --port &?&? --host localhost @ passwordfile Ac;B>$eetutorial%&Be0amplesBcommonBadminpassword.t0tA --user admin hello$.war 'asant deploy-war* App server admin console -et+eans
20
21
http3((localhost3:;:;(hello1(!reetin!
22
23
Web Application
a (.war file or an unpacked directory laid out in the same format as a (.war file 'build directory*
25
)eady to deploy2able package over web container Similar to (.>ar file /ontains things to be deployed
!eb components 'servlets or #S12s* Server-side utility classes Static !eb presentation content '4TM5, image, etc* /lient-side classes 'applets and utility classes*
26
Top-level directory of !A) /ontains #S1 pages, client-side classes and archives, and static !eb resources are stored Also contains !E+-,-. directory
A conte0t is a name that gets mapped to the document root of a !eb application
<hello% is conte0t for hello% e0ample 6istinguishes a !eb application in a single !eb container 4as to be specified as part of client 9)5 27
28
29
,o
7 different ways
30
WE+>$#. Director1
web.0ml ; !eb application deployment descriptor #S1 tag library descriptor files /lasses ; A directory that contains server-side classes; servlets, utility classes, and #ava+eans components lib ; A directory that contains #A) archives of libraries 'tag libraries and any utility libraries called by server-side classes*
33
,TT* re0uest /'@ & Web component /'@ (alias) & "onte2t
http;<<EhostF;EportF<Ere3uest pathFME3uery stringF Ere3uest pathF is made of conte0t and web component2s 9)5 http;<<localhost;?H?H<hello%<greetingMusernameGMonica
/onte0t; -ame of the root document of a web application @ ,dentifies a particular application on that server
<hello% is conte0t
34
36
1rolog Alias 1aths /onte0t and ,nitialiNation 1arameters Event 5isteners .ilter Mappings Error Mappings )eference to Environment Entries, )esource environment entries, or )esources
37
icon, display-name, description, distributable conte0t-param, filter, filter-mapping listener, servet, servlet-mapping, session-config mime-mapping, welcome-file-list error-page, taglib, resource-env-ref, resource-ref security-constraint, login-config, security-role env-entry, e>b-ref, e>b-local-ref
38
*rolo! (o4
eb.2ml)
CM0ml versionGA%.HA encodingGA,SO-??8I-%AMD CQ6O/TR1E web-app 19+5,/ A-<<Sun Microsystems, ,nc.<<6T6 !eb Application $.7<<E-A Ahttp;<<>ava.sun.com<dtd<webappS$S7.dtdAD
39
eb.2ml)
!hen a re3uest is received by Servlet container, it must determine which !eb component in a which web application should handle the re3uest. ,t does so by mapping the 9)5 path contained in the re3uest to a !eb component A 9)5 path contains the conte0t root and alias path
eb.2ml)
Aser-letB Aser-let>nameB!reetin!A(ser-let>nameB Adispla1>nameB!reetin!A(displa1>nameB AdescriptionBno descriptionA(descriptionB Aser-let>classBCreetin!%er-letA(ser-let>classB A(ser-letB Aser-letB Aser-let>nameBresponseA(ser-let>nameB Adispla1>nameBresponseA(displa1>nameB AdescriptionBno descriptionA(descriptionB Aser-let>classB'esponse%er-letA(ser-let>classB A(ser-letB Aser-let>mappin!B Aser-let>nameB!reetin!A(ser-let>nameB Aurl>patternB(!reetin!A(url>patternB A(ser-let>mappin!B Aser-let>mappin!B Aser-let>nameBresponseA(ser-let>nameB Aurl>patternB(responseA(url>patternB A(ser-let>mappin!B
41
)epresents application conte0t /an be shared among !eb components in a !A) file
Cweb-appD ... Cconte0t-paramD Cparam-nameD >ava0.servlet.>sp.>stl.fmt.localiNation/onte0t C<param-nameD Cparam-valueDmessages.+ookstoreMessagesC<param-valueD C<conte0t-paramD ... C<web-appD
42
eb.2ml)
43
eb.2ml)
eb.2ml)
Maps status code ret9)5ed in an 4TT1 response to a #ava programming language e0ception ret9)5ed by any !eb component and a !eb resource
45
'e4erences (o4
eb.2ml)
-eed when web components make references to environment entries, resource environment entries, or resources such as databases E0ample; declare a reference to the data source
Cresource-refD Cres-ref-nameD>dbc<+ook6+C<res-ref-nameD Cres-typeD>ava0.s3l.6ataSourceC<res-typeD Cres-authD/ontainerC<res-authD C<resource-refD
46
E2ample
eb.2ml o4 hello2
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns=" !!p"##$ava.s%n.com#xml#ns#$&ee" version="&.'" xmlns"xsi=" !!p"##www.w(.org#&001#)*+,c ema-ins!ance" xsi"sc ema+oca!ion=" !!p"##$ava.s%n.com#xml#ns#$&ee !!p"##$ava.s%n.com# xml#ns#$&ee#web-app-&-'.xsd"> <displa.-name> ello&<#displa.-name> <servle!> <displa.-name>/ree!ing,ervle!<#displa.-name> <servle!-name>/ree!ing,ervle!<#servle!-name> <servle!-class>servle!s./ree!ing,ervle!<#servle!-class> <#servle!> <servle!> <displa.-name>0esponse,ervle!<#displa.-name> <servle!-name>0esponse,ervle!<#servle!-name> <servle!-class>servle!s.0esponse,ervle!<#servle!-class> <#servle!> <servle!-mapping> <servle!-name>/ree!ing,ervle!<#servle!-name> <%rl-pa!!ern>#gree!ing<#%rl-pa!!ern> <#servle!-mapping> <servle!-mapping> <servle!-name>0esponse,ervle!<#servle!-name> <%rl-pa!!ern>#response<#%rl-pa!!ern> <#servle!-mapping> 47 <#web-app>
*assionE
48