Tải bản đầy đủ (.pdf) (999 trang)

OReilly programming jakarta struts 2nd edition

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.21 MB, 999 trang )










TableofContents
Index
Reviews
ReaderReviews
Errata
Academic

ProgrammingJakartaStruts,2ndEdition
ByChuckCavaness

Publisher :O'Reilly
PubDate :June2004
ISBN :0-596-00651-9
Pages :470


IfyouwanttousetheStrutsFrameworkto
itsfullestpotential,thisisthebookforyou.
ProgrammingJakartaStruts,2ndEdition
coverseverythingthesuccessfulearlier
editiondidaswellasplentymore:nowfully
uptodatewithStruts1.1,thiseditioncovers


thelatestmaterialontaglibrariesandthe
newJavaServerFaces(JSF)APIsandeven
includesall-newchaptersonJSF,JSTL/EL,


andsecurity.











TableofContents
Index
Reviews
ReaderReviews
Errata
Academic

ProgrammingJakartaStruts,2ndEdition
ByChuckCavaness

Publisher :O'Reilly
PubDate :June2004
ISBN :0-596-00651-9

Pages :470



Copyright

Preface
Organization

ConventionsUsedinThisBook




UsingCodeExamples
CommentsandQuestions

Acknowledgments


Chapter1.Introduction
Section1.1.ABriefHistoryoftheWeb




Section1.2.WhatAreJavaServlets?





Section1.4.JSPModel1andModel2Architectures



Section1.6.WhatIsaFramework?

Section1.3.JavaServerPages
Section1.5.WhyIsModel-View-ControllerSoImportant?




Section1.7.AlternativestoStruts


Chapter2.InsidetheWebTier
Section2.1.AnArchitectureOverview

Section2.2.TheHTTPRequest/ResponsePhase




Section2.3.StrutsandScope
Section2.4.UsingURLParameters

Section2.5.ForwardVersusRedirect



Chapter3.OverviewoftheStrutsFramework
Section3.1.ABankingAccountExample




Section3.2.LookingattheBigPicture




Section3.4.StrutsModelComponents




Section3.6.MultipleApplicationSupport

Section3.3.StrutsControllerComponents
Section3.5.StrutsViewComponents
Section3.7.Summary


Chapter4.ConfiguringStrutsApplications
Section4.1.TheStorefrontApplication

Section4.2.WhatIsaWebApplication?





Section4.3.TheWebApplicationDirectoryStructure




Section4.5.Configuringtheweb.xmlFileforStruts




Section4.7.TheDigesterComponent

Section4.4.TheWebApplicationDeploymentDescriptor
Section4.6.TheStrutsConfigurationFile
Section4.8.TheStrutsConsoleTool

Section4.9.ReloadingtheConfigurationFiles


Chapter5.StrutsControllerComponents
Section5.1.TheControllerMechanism

Section5.2.TheUtilitiesClasses


Chapter6.StrutsModelComponents
Section6.1.The"M"inMVC





Section6.2.WhatIsaBusinessObject?
Section6.3.Persistence

Section6.4.WhatDoesStrutsOfferfortheModel?


Chapter7.StrutsViewComponents
Section7.1.WhatIsaView?




Section7.2.WhatAreActionForms?




Section7.4.PerformingPresentationValidation



Section7.6.LookingAheadtoJavaServerFaces

Section7.3.UsingActionErrors
Section7.5.UsingtheDynaActionFormClass





Chapter8.JSPCustomTagLibraries
Section8.1.CustomTagsOverview

Section8.2.TagLibrariesIncludedwithStruts




Section8.3.UsingJavaBeanswithStrutsTags




Section8.5.LogicTags




Section8.7.NestedTags

Section8.4.StrutsHTMLTags
Section8.6.BeanTags
Section8.8.OtherUsefulTagLibraries

Section8.9.TheJSPStandardTagLibrary(JSTL)


Chapter9.ExtendingtheStrutsFramework
Section9.1.WhatAreExtensionPoints?





Section9.2.GeneralExtensionPoints




Section9.4.ExtendingViewComponents

Section9.3.ControllerExtensionPoints
Section9.5.DownsidestoExtendingtheFramework


Chapter10.ExceptionHandling
Section10.1.JavaExceptionHandling

Section10.2.PerformanceImpactofExceptionHandling




Section10.3.SystemVersusApplicationExceptions




Section10.5.ExceptionHandlingProvidedbyStruts


Section10.4.UsingChainedExceptions
Section10.6.TyingUptheLooseEnds

Section10.7.Conclusion


Chapter11.TheValidatorFramework
Section11.1.TheNeedforaValidationFramework




Section11.2.InstallingandConfiguringtheValidator




Section11.4.CreatingYourOwnValidationRules




Section11.6.InternationalizingtheValidation

Section11.3.UsinganActionFormwiththeValidator
Section11.5.TheValidatorandJSPCustomTags
Section11.7.UsingtheValidatorOutsideofStruts


Chapter12.InternationalizationandStruts

Section12.1.WhatIsInternationalization?

Section12.2.SupportforI18NinJava






Section12.3.InternationalizingYourStrutsApplications
Section12.4.ExceptionHandlingandInternationalization
Chapter13.StrutsandEnterpriseJavaBeans
Section13.1.ImplementingtheStorefrontServiceUsingEJB





Section13.2.InterfacingStrutstoEJB

Section13.3.Conclusion


Chapter14.UsingTiles
Section14.1.UnderstandingTemplates




Section14.2.InstallingandConfiguringTiles





Section14.4.TheTilesTagLibrary

Section14.3.UsingTiles
Section14.5.UsingDefinitions

Section14.6.InternationalizationSupportwithTiles


Chapter15.LogginginaStrutsApplication
Section15.1.LogginginaWebApplication




Section15.2.UsingtheServletContainerforLogging




Section15.4.Usingthelog4jPackage




Section15.6.ThePerformanceImpactoflog4j


Section15.3.JakartaCommonsLogging
Section15.5.UsingCommonsLogginginJSPPages
Section15.7.Third-Partylog4jExtensions

Section15.8.Java1.4LoggingAPI


Chapter16.PackagingYourStrutsApplication
Section16.1.ToPackageorNottoPackage




Section16.2.PackagingtheApplicationasaWARFile




Section16.4.CreatinganAutomatedBuildEnvironment

Section16.3.BuildingYourStrutsApplicationswithAnt
Section16.5.RestartingYourServerRemotely


Chapter17.AddressingPerformance
Section17.1.WhatIsGoodPerformance?

Section17.2.PerformanceVersusLoadTesting





Section17.3.Performance-andStress-TestingTools
Section17.4.TestingtheStorefrontApplication

Section17.5.PerformanceandScalabilityGotchas


Chapter18.JavaServerFaces
Section18.1.StrutsandJavaServerFaces




Section18.2.OverviewofJSFArchitecture




Section18.4.ConvertingExistingStrutsApplicationstoJSF

Section18.3.InstallingandRunningtheExampleStruts-FacesApplication
Section18.5.FurtherReading


AppendixA.ChangesSinceStruts1.0
SectionA.1.ActionServletandRequestProcessor






SectionA.2.ModificationstotheStrutsActionClass



SectionA.3.Changestoweb.xmlandstruts-config.xml




SectionA.4.ActionStaticsChanged




SectionA.6.NewFeaturesofStruts1.1




SectionA.8.ChangetoCommonsLogging




SectionA.10.DeprecationoftheGenericDataSource

SectionA.5.TagUtilsandModuleUtils
SectionA.7.TheStrutsValidator

SectionA.9.RemovalofAdminActions
SectionA.11.DependencyonCommonsProjects


AppendixB.DownloadingandInstallingStruts
SectionB.1.TheBinaryVersusSourceDistributions

SectionB.2.TipsonInstallingStrutsinTomcat




SectionB.3.TipsonInstallingStrutsinWebLogic
SectionB.4.TipsonInstallingStrutsinWebSphere


AppendixC.Resources
SectionC.1.TheStrutsMailingLists

SectionC.2.TheStrutsResourceWebPage




SectionC.3.TilesSite




SectionC.5.TheStrutsConsole





SectionC.4.NestedTagsSite
SectionC.6.EasyStrutsProject
Colophon
Index


Copyright©2004O'ReillyMedia,Inc.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reillybooksmaybepurchasedforeducational,business,or
salespromotionaluse.Onlineeditionsarealsoavailablefor
mosttitles().Formoreinformation,
contactourcorporate/institutionalsalesdepartment:(800)
998-9938or
NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
TheJavaSeries,ProgrammingJakartaStruts,theimageofa
percheron,andrelatedtradedressaretrademarksofO'Reilly
Media,Inc.
Java™andallJava-basedtrademarksandlogosaretrademarks
orregisteredtrademarksofSunMicrosystems,Inc.,inthe
UnitedStatesandothercountries.Manyofthedesignations
usedbymanufacturersandsellerstodistinguishtheirproducts
areclaimedastrademarks.Wherethosedesignationsappearin
thisbook,andO'ReillyMedia,Inc.wasawareofatrademark

claim,thedesignationshavebeenprintedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorsassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.


Preface
Overthelastfewyears,webdevelopmenthasturnedavery
importantcorner.GonearethedayswhenJava™developers
wrestledwithasingleJSPthatcontainedpresentationlogic,
databaseaccessviaSQL,andnavigationalintelligence.Java
webdevelopershavelearnedfromtheirmistakes,paidtheprice
indebuggingandmaintenancetime,andmovedon.
Thenumberandvarietyofreadilyavailablewebframeworks
todayisimmense.It'shardtopointabrowserataJava
technicalsitewithoutfindinganewlyreleasedwebframework
that'sgoingtorevolutionizethemodernworld.Whilesomemay
seethisasabadthingthatmightdividetheJavacommunity,
thetruthisthattheconstantemergenceofnewframeworksis
justevolutionatwork.
Thedesignandconstructionoftoday'snontrivialweb
applicationspushesdeveloperstothelimitofwhat'slogically
andphysicallypossible.Myriadsolutionsarethrownatthe
problemstheseapplicationspresent.Someofthesolutions
stick,andaswithhumanevolution,valuablecharacteristicsare
passedoninfuturegenerationsofsoftware.Othersolutionsdo
notthosethatfailtoservetheneedsofusersandaddvalue
usuallyfallbythewayside.
Throughthisevolutionaryprocess,theJakartaStruts

framework(createdbyCraigR.McClanahananddonatedtothe
ApacheSoftwareFoundationin2000)hasemergedasoneof
thebestwebframeworksavailable.ThisbookcoversVersion
1.1,whichcontainsmanymajorenhancementsoverthe
previousJakartaStrutsrelease.Ifyouarebuildingapplications,
web-basedornot,oneofthemainthingsyouwilllearnfrom
thisbookisthatframeworkssuchasStrutsareagreattime
investment.


Organization
Thisbookbeginswithapreliminarydiscussionthatlaysthe
groundworkfortherestofthematerial.Thisdiscussionwillbe
arefresherforsomeandcompletelynewforothers.From
there,weexplorethecomponentsofStruts'sMVC
implementation,includingalookattheJSPcustomtagsthat
arepartoftheframework.Then,toroundoutyour
understandingofthevalueoftheStrutsframework,welookat
severalcomplicatedbutimportanttopicsrelatedtobuilding
web-basedapplications.

Chapter1,Introduction
Thischapterdiscussessomepreliminaryconcepts,suchas
theMVCpattern,Model2,andtheideaofasoftware
framework.Althoughmanydevelopersmayalreadybe
familiarwithsomeoralloftheideaspresentedhere,Iwant
toensurethatallreadersarestartingfromthesameplace.
Theconceptspresentedinthischapterhelptolaythe
foundationfortherestofthebook.


Chapter2,InsidetheWebTier
TheStrutsframeworkisbasedontheJavaServlet
technologyand,toalesserextent,JavaServerPages,and
thereforeistightlycoupledtoawebcontainer.ForStruts
developers,understandinghowthewebcontainerprocesses
clientrequestsisfundamentaltounderstandingthe
frameworkitself.Thischapterdiscussesthecomponentsof
thewebcontainerandtheresponsibilitiesofeach.


Chapter3,OverviewoftheStrutsFramework
ThischapterprovidesanoverviewoftheStrutsframework;
itdoesnotattempttocoverallofthefeaturesorgointo
significantdepth.Itemphasizeshowallthepiecesfitinto
theMVCandModel2architecturepresentedinChapter1.

Chapter4,ConfiguringStrutsApplications
TheStrutsframeworkusestwoseparatebutsomewhat
relatedtypesofconfigurationfiles,whichmustbe
configuredproperlybeforeanapplicationwillfunction
properly.DuetothepopularityandflexibilityofXML,both
typesofconfigurationfilesarebasedonXML.Thischapter
presentsthesyntaxofthefiles.

Chapter5,StrutsControllerComponents
TheStrutsframeworkusesaservlettoprocessincoming
requests;however,itreliesonmanyothercomponentsthat
arepartofthecontrollerdomaintohelpitcarryoutits
responsibilities.Thischaptertakesin-depthlookatthe
componentsthatareresponsibleforthecontroller

functionalityintheframework.

Chapter6,StrutsModelComponents
Thischapterintroducesthecomponentsthatmakeupthe
modelportionofaStrutsapplication.Themodelrepresents
thebusinessdataforanapplicationandshouldclosely
resemblethereal-worldentitiesandbusinessprocessesfor


theorganization.Thischapterexplorestherolesand
responsibilitiesofthemodelcomponentswithintheStruts
frameworkandfocusesonbuildinganarchitecturallycorrect
implementationfortheStorefrontapplication.Special
attentionisgiventousingapersistenceframeworkthatcan
beintegratedintoaStrutsapplicationeasilyand
effortlessly.

Chapter7,StrutsViewComponents
Thischapterintroducesthecomponentsthatmakeupthe
viewportionoftheStrutsframework.Theframeworkuses
theviewcomponentstorenderdynamiccontentforthe
client.BasedprimarilyonJavaServerPages,the
componentsprovidesupportforinternationalized
applicationsaswellasforuser-inputacceptance,validation,
anderrorhandling,allofwhichmakeiteasierforthe
developertofocusonbusinessrequirements.Thischapter
concludesthethree-partdiscussionofhowtheStruts
frameworkimplementstheMVCpattern.

Chapter8,JSPCustomTagLibraries

Thischapterlooksatthedifferentcategoriesoftagsand
howtheycanhelpmakedevelopingapplicationswiththe
Strutsframeworkeveneasier.Itisnotmeanttobean
exhaustivereferenceforeverytagthat'spartoftheStruts
taglibrariesthatinformationcanbefoundwithintheStruts
userguideorJavaDocs.Therealpurposeofthischapteris
toputforththebenefitsofusingtheStrutstaglibrariesand
toprovideafewstrategiesthatcanhelpmaketheswitchto
usingthetagslesspainful.


Chapter9,ExtendingtheStrutsFramework
Oneofthebiggestadvantagesofusingaframeworkisthe
abilitytoextendandcustomizeitbasedontheneedsofthe
application.TheStrutsframeworkisnoexception;it
providesseveralimportantextensionpointsfordevelopers.
Thischaptertakesaquickglanceatseveralofthose
extensionpointsandexaminesthebenefitsanddrawbacks
ofextendingtheframework.

Chapter10,ExceptionHandling
ThischapterlooksathowtousetheJavaexceptionhandlingmechanismwithinyourStrutsapplicationstomake
themmorerobustandallowthemtorespondgracefully
whenthingsdon'tgoasexpected.Specialattentionisgiven
tothedifferencesbetweenperformingtheexception
handlingprogrammaticallyandusingthenewdeclarative
featureaddedtotheStrutsframeworkinVersion1.1.

Chapter11,TheValidatorFramework
ThischapterintroducestheValidatorframework,whichwas

createdspecificallytoworkwithStrutscomponents.The
Validatorallowsyoutodeclarativelyconfigurevalidation
routinesforaStrutsapplicationwithouthavingtoprogram
specialvalidationlogic.

Chapter12,InternationalizationandStruts
ThischapterfocusesonwhatittakestomakeaStruts
applicationavailabletocustomersfromaroundtheworld,
regardlessoftheirlanguageorgeographicallocation.Asis


oftenthecaseinsoftwaredevelopment,planningaheadis
themostimportantthingthatyoucandotohelpensure
success.Afterreadingthischapter,youshouldbeableto
buildStrutsapplicationsthatcansupportabroadrangeof
customers.

Chapter13,StrutsandEnterpriseJavaBeans
Thischaptercoverstheissuesyouneedtoconsiderwhen
developinganinterfacebetweenyourStrutsactionsandan
applicationtier.Itfocusesoninterfacingtoamodelbuilt
usingEnterpriseJavaBeans™(EJB).

Chapter14,UsingTiles
ThischapterlooksattheTilesframework,whichnowispart
ofthecoreStrutsdistribution.TheTilesframeworkisan
advancedtemplatingframeworkthatreducestheamountof
redundantcodeawebapplicationcontainsandallows
developerstobetterseparatecontentfromlayout.


Chapter15,LogginginaStrutsApplication
ThischapterexamineshowtheuseoflogginginyourStruts
applicationscanhelpyouidentifydefectsbeforethe
applicationsgetintoproductionand,ifyoursoftware
alreadyisbeingusedinproduction,howloggingcanhelp
youidentifyproblemsandarriveatsolutionsmuchmore
quickly.

Chapter16,PackagingYourStrutsApplication


Thischapterdiscussesthebestpracticesforpackagingand
deployingaStrutsapplicationandwhatittakesto
automatethebuildprocessforyourenvironment.Special
coverageisgiventoAnt,theJava-basedbuildtoolavailable
fromJakarta.

Chapter17,AddressingPerformance
Thischapterexplorestheperformanceimplicationsofusing
theStrutsframeworkanditsassociatedtechnologiesto
buildwebapplicationsanddiscusseshowcertaindesignand
programmingdecisionsaffecttheoverallperformanceofthe
applications.Itcoversperformance,load,andstress
testing,andthestepsnecessarytocarryouteach.

Chapter18,JavaServerFaces
ThischapterprovidesanoverviewofyetanotherJava
technologybeingbirthedfromtheJavaCommunity.
JavaServerFacesprovidessomepromisingcontinuationfor
theJavawebdevelopmentcommunity.Althoughsome

overlapexistsbetweenStrutsandJSF,thereisplentyof
roomforbothandthischapterexploreswhatthat
integrationlookslike.

AppendixA,ChangesSinceStruts1.0
Thisappendixenumeratesthenewfeatureswithinthe1.1
release.

AppendixB,DownloadingandInstallingStruts


Thisappendixdiscussesthestepsfordownloadingand
installingStrutsinyourenvironment.

AppendixC,Resources
Thisappendixlistsseveralresourcesthatcanhelpincrease
yourknowledgeonceyou'vemasteredtheconceptsinthis
book.


ConventionsUsedinThisBook
Thefollowingfontconventionsareusedinthisbook:
Italicisusedfor:
Unixpathnames,filenames,andprogramnames
Internetaddresses,suchasdomainnamesandURLs
Newtermswheretheyaredefined
Boldfaceisusedfor:
NamesofGUIitems(windownames,buttons,menu
choices,etc.)
Constantwidthisusedfor:

Commandlinesandoptionsthatshouldbetypedverbatim
NamesandkeywordsinJavaprograms,includingmethod
names,variablenames,andclassnames
XMLelementnamesandtags,attributenames,andother
XMLconstructsthatappearastheywouldwithinanXML
document

Indicatesatip,suggestion,orgeneralnote.


Indicatesawarningorcaution.


UsingCodeExamples
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdonotneedtocontactusforpermission
unlessyou'rereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesnotrequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesnotrequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdonotrequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"ProgrammingJakartaStruts,SecondEdition,by
ChuckCavaness.Copyright2004O'ReillyMedia,Inc.,0-59600651-9."

Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseor
thepermissiongivenabove,feelfreetocontactusat



CommentsandQuestions
Pleaseaddresscommentsandquestionsconcerningthisbookto
thepublisher:
O'ReillyMedia,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
800-998-9938(intheU.S.orCanada)
707-829-0515(internationalorlocal)
707-829-0104(fax)
Thereisawebpageforthisbook,whichlistserrata,examples,
andadditionalinformation.Youcanaccessthispageat:
/>Tocommentorasktechnicalquestionsaboutthisbook,send
emailto:

Formoreinformationaboutbooks,conferences,Resource
Centers,andtheO'ReillyNetwork,seetheO'Reillywebsiteat:



Acknowledgments
Writingabookofthistypeisnevertheworkofjustoneperson;
itliterallytakesanarmyofhardenedsoldiers,andthisbookis
noexception.Fromtheeditorstothemarketingorganizationto
thereviewersofthemanuscript,thisbooksimplywouldnot
havebeenpossiblewithoutthegroupofdedicatedfolksthat

gaveupmanyoftheirnightsandweekendstohelpensurethat
thequalitywasthehighestpossible.Anycreditshouldbegiven
toallofthegreatpeopleinvolved;anymistakesaremine
alone.
First,IneedtothankmyO'Reillyeditors,BrettMcLaughlinand
RobertEckstein,twoofthemostdedicatedandsincereeditors
thatIhaveworkedwith.Ihopewehaveachancetowork
togetheronfutureprojects.Youradviceandleadershipmade
thetaskmucheasierthanIcouldhaveimagined.Ialsowould
liketothankKyleHartfromO'Reilly'smarketingdepartment.
Yourhelpwasdearlyappreciated.
Next,Iwouldliketoacknowledgetheteamoffinedevelopers
thatIfirstlearnedStrutswith.ThebondthatourlittleNVteam
hadwassomethingspecialthatcomesaroundonlyonceina
while.Ireallyenjoyedworkingwithallofyou.
Thefollowingpeopleplayedaspecialrolebygivingmeadvice
onthebook'scontentanddirection:SteveArdis,JillEntinger,
SeeYamLim,andTedHusted(althoughTedmaynotrealize
thathecontributedinthisway).
WhenIfirstdecidedtopostthedraftchaptersofthebook,I
madeacommentthatifanyreviewerswentbeyondthecallof
duty,Iwouldpersonallythankthemintheacknowledgmentsof
thebook.LittledidIrealizehowmanywouldtakemeuponit!
TherearesomanythatIcan'tthankeachandeveryone
individually.Over100peoplecontributedfeedbackforoneor


morechaptersofthisbook.TheStrutscommunityisbyfarone
ofthebest.AlmosteverypersonontheStrutsmailinglisthas
contributedinonewayoranother.Toeachofyou,thankyou!

Thankstothefollowingpeople:JohnGuthrie,DavidKarr,Brent
Kyle,StefanoScheda,andRickReumannforaskingalltheright
questions,MarkGalbreathforremindingmeofmy10th-grade
Englishteacher,andJamesMitchellandJamesHolmesfor
gettingmeinvolvedwiththeAtlantaStrutsgroup.
IneedtosayaspecialthankstoTimDruryforhishelpon
Chapter16.HisAntskillsareknownworldwide.Specialthanks
alsotoBrianKeeton,whowroteChapter13becauseI'mtoo
slowhe'sthesmartestEJBdeveloperIknow.Bothofyouare
greatfriendsandsimplythefinesthumansthatI'veevermet.
Justknowingyouhasmademeabetterperson.Ihopewecan
worktogetheragain.
ThegroupatTheServerSide.comdeservesspecialthanksfrom
meandthereviewersforallowingthedraftchaptersofthis
booktobeavailablefordownload.Thisisagreatexampleof
whatthefutureholdsforbookpublishing.
IwouldberemissifIdidn'tthanktheentireStrutscommunity.
Ihavemetandcorrespondedwithmanysmartdeveloperswho
alsostrikemeasjustreallyfunpeopletohangaroundwith.
ThefeedbackandsuggestionsIreceivedduringthisprocess
wereawesome.Ihopethatallofyougotsomebenefitoutof
this,andIappreciateeveryone'spatiencewhilesomeofthis
wasfiguredoutasIwent.
Finally,allStrutsdevelopersshouldgivethankstoCraig
McClanahanforhavingthewitsabouthimtocreatethe
frameworkandmakeitfreelyavailabletothecommunity.He
couldhavetriedtomakeaprofitfromitbystartingStruts,Inc.,
butherealizedthathewouldberewardedten-foldanyway,and
I'msurehehasbeen.Craig,it'saniceframework,youshould
beproud.AndtoallofthecommittersontheStrutsproject,



whatwoulditreallybewithoutyou?Thanksforallofyourhelp.


Chapter1.Introduction
TheStrutsopensourceframeworkwascreatedtomakeit
easierfordeveloperstobuildwebapplicationsbasedonthe
JavaServletandJavaServerPages(JSP)technologies.Likea
building,awebapplicationmusthaveasolidfoundationfrom
whichtherestofthestructurecangrow.TheStrutsframework
providesdeveloperswithaunifiedinfrastructureuponwhich
Internetapplicationscanbebased.UsingStrutsasthe
foundationallowsdeveloperstoconcentrateonbuildingthe
businessapplicationratherthanontheinfrastructure.
TheStrutsframeworkwascreatedbyCraigR.McClanahanand
donatedtotheApacheSoftwareFoundation(ASF)in2000.The
projectnowhasseveralcommittersfromaroundtheworld,and
manydevelopersarecontributingtotheoverallgoodofthe
framework.TheStrutsframeworkisoneofmanywell-known
andsuccessfulApacheJakartaprojects.OthersincludeAnt,
log4j,andTomcat.TheoverallmissionoftheJakartaprojectis
toprovidecommercial-qualityserversolutions,basedonthe
Javaplatform,inanopenandcooperativefashion.


1.1ABriefHistoryoftheWeb
Nobookonwebtechnologywouldbecompletewithoutabrief
lookathowtheWorldWideWeb(WWW)hasbecomeas
popularasitistoday.TheWebhascomealongwaysincethe

dayswhenthefirsthypertextdocumentsweresentoverthe
Internet.In1989,whenthephysicistsattheCERNlaboratory
proposedtheideaofsharingresearchinformationbetween
researchersusinghypertextdocuments,theyhadnoideahow
bigtheWebwouldgroworhowessentialitwouldbecometo
dailylifeformuchoftheindustrializedworld.TheWebisnow
anacceptedpartofourvernacular.
IttookawhileforthebenefitsofusingtheWebtobecome
cleartoothersoutsideofCERN,butasweallknow,it
eventuallyeruptedintowhatweusetoday.Fromitsbeginnings,
theWebwasdesignedfordealingwithstaticdocuments,butit
wasanaturalprogressiontowanttheabilitytogenerate
documentcontentdynamically.TheCommonGatewayInterface
(CGI)wascreatedtodothatverything.CGIisastandardthat
allowswebserverstointeractwithexternalapplicationsinsuch
awaythathypertextpagesnolongerhavetobestatic.ACGI
programcanretrieveresultsfromadatabaseandinsertthose
resultsasatableinahypertextdocument.Likewise,data
enteredintoahypertextpagecanbeinsertedintothe
database.Thistechnologyopenedupinfinitepossibilitiesand,
infact,startedtheInternetcrazeofthemid-1990sandtoday.
AlthoughCGIapplicationsareverygoodatwhattheydo,there
aresomeseriouslimitationstothisapproach.Foronething,
CGIapplicationsareveryresource-intensive.Anewoperating
system(OS)heavyweightprocessiscreatedtohandleevery
requestthatcomesfromabrowser.OncetheCGIscriptis
finishedexecuting,theprocesshastobereclaimedbytheOS.
Thisconstantstartingandstoppingofheavyweightprocessesis
terriblyinefficient.Youcanimaginehowbadtheresponsetime



×