LearnJavaforWeb,java怎么做网站

怎么做 4
LearnJavaforWebDevelopment VishalLayka LearnJavaforWebDevelopment Copyright©2014byVishalLayka Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpartofthematerialisconcerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation,broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,andtransmissionorinformationstorageandretrieval,electronicadaptation,putersoftware,orbysimilarordissimilarmethodologynowknownorhereafterdeveloped.Exemptedfromthislegalreservationarebriefexcerptsinconnectionwithreviewsorscholarlyanalysisormaterialsuppliedspecificallyforthepurposeofbeingenteredandexecutedonputersystem,forexclusiveusebythepurchaserofthework.DuplicationofthispublicationorpartsthereofispermittedonlyundertheprovisionsoftheCopyrightLawofthePublisher’slocation,initscurrentversion,andpermissionforusemustalwaysbeobtainedfromSpringer.PermissionsforusemaybeobtainedthroughRightsLinkattheCopyrightClearanceCenter.ViolationsareliabletoprosecutionundertherespectiveCopyrightLaw. ISBN-13(pbk):978-1-4302-5983-
1 ISBN-13(electronic):978-1-4302-5984-
8 Trademarkednames,logos,andimagesmayappearinthisbook.Ratherthanuseatrademarksymbolwitheveryurrenceofatrademarkedname,logo,orimageweusethenames,logos,andimagesonlyinaneditorialfashionandtothebenefitofthetrademarkowner,withnointentionofinfringementofthetrademark. Theuseinthispublicationoftradenames,trademarks,servicemarks,andsimilarterms,eveniftheyarenotidentifiedassuch,isnottobetakenasanexpressionofopinionastowhetherornottheyaresubjecttoproprietaryrights. Whiletheadviceandinformationinthisbookarebelievedtobetrueandurateatthedateofpublication,neithertheauthorsnortheeditorsnorthepublishercaneptanylegalresponsibilityforanyerrorsoromissionsthatmaybemade.Thepublishermakesnowarranty,expressorimplied,withrespecttothematerialcontainedherein. PresidentandPublisher:PaulManningLeadEditor:SteveAnglinDevelopmentEditor:MatthewMoodie,ChrisNelson,TomWelshTechnicalReviewer:BorisMinkinEditorialBoard:SteveAnglin,MarkBeckner,EwanBuckingham,GaryCornell,LouiseCorrigan, JamesT.DeWolf,JonathanGennick,JonathanHassell,RobertHutchinson,MichelleLowman,JamesMarkham,MatthewMoodie,JeffOlson,JeffreyPepper,DouglasPundick,BenRenow-Clarke,DominicShakeshaft,GwenanSpearing,MattWade,SteveWeissCoordinatingEditor:AnamikaPanchooCopyEditor:KimWimpsettCompositor:SPiGlobalIndexer:SPiGlobalArtist:SPiGlobalCoverDesigner:AnnaIshchenko DistributedtothebooktradeworldwidebySpringerScience+BusinessMediaNewYork,233SpringStreet,6thFloor,NewYork,NY10013.Phone1-800-SPRINGER,fax(201)348-4505,e-mailorders-ny@,orvisit.ApressMedia,LLCisaCaliforniaLLCandthesolemember(owner)isSpringerScience+BusinessMediaFinanceInc(SSBMFinanceInc).SSBMFinanceIncisaDelawarecorporation. Forinformationontranslations,pleasee-mailrights@,orvisit. ApressandfriendsofEDbooksmaybepurchasedinbulkforacademic,corporate,orpromotionaluse.eBookversionsandlicensesarealsoavailableformosttitles.Formoreinformation,referenceourSpecialBulkSales–eBookLicensingwebpageat/bulk-sales. Anysourcecodeorothersupplementarymaterialsreferencedbytheauthorinthistextisavailabletoreadersat.Fordetailedinformationabouthowtolocateyourbook’ssourcecode,goto/source-code/. Tothefourstarsinmyuniverse:myparents,ShobhaandMadan,andmybrothers,DeepakandNishant.          ContentsataGlance AbouttheAuthor����������������������������������������������������������������������������������������������������������������xvAbouttheTechnicalReviewer������������������������������������������������������������������������������������������xviiIntroduction�����������������������������������������������������������������������������������������������������������������������xix■■Chapter1:IntroducingJavaWebDevelopment����������������������������������������������������������������1■■Chapter2:BuildingWebApplicationsUsingServletsandJSP���������������������������������������43■■Chapter3:BestPracticesinJavaEEWebDevelopment�����������������������������������������������105■■Chapter4:BuildingaWebApplicationUsingStruts2��������������������������������������������������161■■Chapter5:BuildingJavaWebApplicationswithSpringWebMVC�������������������������������203■■Chapter6:Component-BasedWebDevelopmentUsingJSF2��������������������������������������263■■Chapter7:RapidWebDevelopmentwithGrails������������������������������������������������������������299■■Chapter8:PlaywithJavaandScala�����������������������������������������������������������������������������355■■AppendixA:IntroductiontoJava����������������������������������������������������������������������������������383■■AppendixB:IntroductiontoGroovy�������������������������������������������������������������������������������399■■AppendixC:IntroductiontoScala���������������������������������������������������������������������������������423Index���������������������������������������������������������������������������������������������������������������������������������435 v          Contents AbouttheAuthor����������������������������������������������������������������������������������������������������������������xvAbouttheTechnicalReviewer������������������������������������������������������������������������������������������xviiIntroduction�����������������������������������������������������������������������������������������������������������������������xix■■Chapter1:IntroducingJavaWebDevelopment����������������������������������������������������������������
1 JVMLanguages�����������������������������������������������������������������������������������������������������������������������������
2 LanguagesDesignedfortheJVM�������������������������������������������������������������������������������������������������������������������������2LanguagesPortedtotheJVM��������������������������������������������������������������������������������������������������������������������������������
3 JavaEE������������������������������������������������������������������������������������������������������������������������������������������
4 TheJavaEEPlatform���������������������������������������������������������������������������������������������������������������������������������������������5TheClientTier��������������������������������������������������������������������������������������������������������������������������������������������������������6TheWebTier����������������������������������������������������������������������������������������������������������������������������������������������������������
6 JavaWebFrameworks����������������������������������������������������������������������������������������������������������������10GettingStartedwithJava������������������������������������������������������������������������������������������������������������11 SettingUptheDevelopmentEnvironment�����������������������������������������������������������������������������������������������������������12CreatingandRunningYourFirstJavaApplication�����������������������������������������������������������������������������������������������12RunningYourJavaApplication����������������������������������������������������������������������������������������������������������������������������13DevelopingJavaApplicationswithanIDE�����������������������������������������������������������������������������������������������������������13 vii viiiContents TheBookstoreApplication�����������������������������������������������������������������������������������������������������������19DataModelfortheBookstoreApplication�����������������������������������������������������������������������������������20 DataessLayerfortheBookstoreApplication������������������������������������������������������������������������������������������������25ClientfortheDataessLayer�������������������������������������������������������������������������������������������������������������������������33 TrendsandTechnologiesintheJavaWebLandscape����������������������������������������������������������������35 ResponsiveWebApplications������������������������������������������������������������������������������������������������������������������������������35Single-PageWebApplication(SPA)���������������������������������������������������������������������������������������������������������������������38Real-TimeWebApplication����������������������������������������������������������������������������������������������������������������������������������38ReactiveWebApplication������������������������������������������������������������������������������������������������������������������������������������39MashupsandWebServices���������������������������������������������������������������������������������������������������������������������������������39SemanticWeb(Web3.0)��������������������������������������������������������������������������������������������������������������������������������������41 Summary�������������������������������������������������������������������������������������������������������������������������������������41■■Chapter2:BuildingWebApplicationsUsingServletsandJSP���������������������������������������43 Servlets���������������������������������������������������������������������������������������������������������������������������������������45 YourFirstWebApplicationUsingaServlet���������������������������������������������������������������������������������������������������������47ServletContextandServletConfig�����������������������������������������������������������������������������������������������������������������������62RequestDispatcher����������������������������������������������������������������������������������������������������������������������������������������������64Filters������������������������������������������������������������������������������������������������������������������������������������������������������������������65ConfiguringServletviaAnnotations��������������������������������������������������������������������������������������������������������������������67 JavaServerPages�����������������������������������������������������������������������������������������������������������������������71 YourFirstWebApplicationUsingJSP�����������������������������������������������������������������������������������������������������������������71JSPBasics�����������������������������������������������������������������������������������������������������������������������������������������������������������75 TheMVCPattern��������������������������������������������������������������������������������������������������������������������������86BookstoreApplication�����������������������������������������������������������������������������������������������������������������87 HomePage����������������������������������������������������������������������������������������������������������������������������������������������������������88ListingAlltheBooks��������������������������������������������������������������������������������������������������������������������������������������������94SearchingtheBooksbyCategory�����������������������������������������������������������������������������������������������������������������������96SearchingtheBooksbyKeyword�����������������������������������������������������������������������������������������������������������������������98 Summary����������������������������������������������������������������������������������������������������������������������������������103 Contents ix ■■Chapter3:BestPracticesinJavaEEWebDevelopment�����������������������������������������������105Best-PracticeSolutions:UsingELandJSTL�����������������������������������������������������������������������������107 ExpressionLanguage����������������������������������������������������������������������������������������������������������������������������������������109JSTL�������������������������������������������������������������������������������������������������������������������������������������������������������������������128 Best-PracticeSolutions:UsingPatterns������������������������������������������������������������������������������������146 InterceptingFilter����������������������������������������������������������������������������������������������������������������������������������������������147FrontController��������������������������������������������������������������������������������������������������������������������������������������������������149ViewHelper�������������������������������������������������������������������������������������������������������������������������������������������������������151CompositeView�������������������������������������������������������������������������������������������������������������������������������������������������152DispatcherView�������������������������������������������������������������������������������������������������������������������������������������������������153ServicetoWorker����������������������������������������������������������������������������������������������������������������������������������������������155 JavaWebFrameworks��������������������������������������������������������������������������������������������������������������158 WhyUseaFramework?
�������������������������������������������������������������������������������������������������������������������������������������159 Summary����������������������������������������������������������������������������������������������������������������������������������160■■Chapter4:BuildingaWebApplicationUsingStruts2��������������������������������������������������161 Struts2FrameworkOverview��������������������������������������������������������������������������������������������������161Action����������������������������������������������������������������������������������������������������������������������������������������164 ActionInterface�������������������������������������������������������������������������������������������������������������������������������������������������165ActionSupportClass������������������������������������������������������������������������������������������������������������������������������������������166 Interceptors������������������������������������������������������������������������������������������������������������������������������167ValueStackandOGNL���������������������������������������������������������������������������������������������������������������168ResultTypeandResult���������������������������������������������������������������������������������������������������������������168Struts2Tags����������������������������������������������������������������������������������������������������������������������������169GettingStartedwithStruts2�����������������������������������������������������������������������������������������������������169BookstoreWebApplication��������������������������������������������������������������������������������������������������������183 TheLoginFunctionality������������������������������������������������������������������������������������������������������������������������������������183DevelopingTemplates����������������������������������������������������������������������������������������������������������������������������������������188IntegratingtheDataessLayer��������������������������������������������������������������������������������������������������������������������195 Summary����������������������������������������������������������������������������������������������������������������������������������201 x Contents ■■Chapter5:BuildingJavaWebApplicationswithSpringWebMVC�������������������������������203SpringFrameworkOverview�����������������������������������������������������������������������������������������������������204 AOPandInstrumentation�����������������������������������������������������������������������������������������������������������������������������������204CoreContainer���������������������������������������������������������������������������������������������������������������������������������������������������204Dataess/Integration������������������������������������������������������������������������������������������������������������������������������������205Test��������������������������������������������������������������������������������������������������������������������������������������������������������������������205Web��������������������������������������������������������������������������������������������������������������������������������������������������������������������205 SpringFrameworkFundamentals��������������������������������������������������������������������������������������������206 ApplicationContext��������������������������������������������������������������������������������������������������������������������������������������������211 KeyObjectivesoftheSpringFramework����������������������������������������������������������������������������������212 DealingwithTightCouplingUsingDependencyInjection����������������������������������������������������������������������������������212AddressingCross-CuttingConcernsUsingAOP������������������������������������������������������������������������������������������������217RemovingBoilerplateCodeUsingTemplates����������������������������������������������������������������������������������������������������221 BuildingWebApplicationwithSpringWebMVC����������������������������������������������������������������������227 SpringWebMVCArchitecture����������������������������������������������������������������������������������������������������������������������������227GettingStartedwithaSpringWebMVCApplication������������������������������������������������������������������������������������������232ImplementingSpringWebMVCintheBookstoreApplication���������������������������������������������������������������������������245WorkingwithFormsUsingAnnotations�������������������������������������������������������������������������������������������������������������251Annotations-BasedValidation����������������������������������������������������������������������������������������������������������������������������257 Summary�����������������������������������������������������������������������������������������������������������������������������������261■■Chapter6:Component-BasedWebDevelopmentUsingJSF2��������������������������������������263 TheArchitectureofJSF�������������������������������������������������������������������������������������������������������������264 FacesServlet������������������������������������������������������������������������������������������������������������������������������������������������������264ManagedBean���������������������������������������������������������������������������������������������������������������������������������������������������264VDL��������������������������������������������������������������������������������������������������������������������������������������������������������������������265JSFEL����������������������������������������������������������������������������������������������������������������������������������������������������������������265JSFTagLibrary��������������������������������������������������������������������������������������������������������������������������������������������������265UIComponent����������������������������������������������������������������������������������������������������������������������������������������������������266Renderer������������������������������������������������������������������������������������������������������������������������������������������������������������266ConverterandValidator�������������������������������������������������������������������������������������������������������������������������������������267EventsandEventListeners�������������������������������������������������������������������������������������������������������������������������������267 Contents xi GettingStartedwithJSF�����������������������������������������������������������������������������������������������������������267LifeCycleofaJSFApplication��������������������������������������������������������������������������������������������������277 Phase1:RestoreView���������������������������������������������������������������������������������������������������������������������������������������278Phase2:ApplyRequestValues��������������������������������������������������������������������������������������������������������������������������278Phase3:ProcessValidation�������������������������������������������������������������������������������������������������������������������������������278Phase4:UpdateModel�������������������������������������������������������������������������������������������������������������������������������������278Phase5:InvokeApplication�������������������������������������������������������������������������������������������������������������������������������279Phase6:RenderResponse��������������������������������������������������������������������������������������������������������������������������������279 ManagedBeans�������������������������������������������������������������������������������������������������������������������������281Facelets�������������������������������������������������������������������������������������������������������������������������������������282 TemplatingwithFacelets�����������������������������������������������������������������������������������������������������������������������������������282 BuildingtheBookstoreApplicationUsingJSF2�����������������������������������������������������������������������288 IntegratingJSFwithSpringFramework������������������������������������������������������������������������������������������������������������290essingaDatabasefromtheWebLayerviaSpringJDBCTemplate��������������������������������������������������������������291DevelopingTemplates���������������������������������������������������������������������������������������������������������������������������������������293DevelopingtheUserInterfaceUsingUIComponentsandJSFEL���������������������������������������������������������������������294 Summary�����������������������������������������������������������������������������������������������������������������������������������298■■Chapter7:RapidWebDevelopmentwithGrails������������������������������������������������������������299 GrailsFeatures��������������������������������������������������������������������������������������������������������������������������299 ConventionoverConfiguration��������������������������������������������������������������������������������������������������������������������������300Scaffolding��������������������������������������������������������������������������������������������������������������������������������������������������������300Object-RelationalMapping��������������������������������������������������������������������������������������������������������������������������������300Plug-Ins�������������������������������������������������������������������������������������������������������������������������������������������������������������301UnitTesting��������������������������������������������������������������������������������������������������������������������������������������������������������301IntegratedOpenSource�������������������������������������������������������������������������������������������������������������������������������������301 InstallingGrails��������������������������������������������������������������������������������������������������������������������������302HelloWorldApplication�������������������������������������������������������������������������������������������������������������302BookstoreApplication���������������������������������������������������������������������������������������������������������������305 CreatingtheBookstoreApplication�������������������������������������������������������������������������������������������������������������������305RunningtheApplication�������������������������������������������������������������������������������������������������������������������������������������312CreatingtheController��������������������������������������������������������������������������������������������������������������������������������������314 xii Contents TestingtheController���������������������������������������������������������������������������������������������������������������������������������������317CreatingaDomainClass�����������������������������������������������������������������������������������������������������������������������������������321 Scaffolding��������������������������������������������������������������������������������������������������������������������������������325 DynamicScaffolding������������������������������������������������������������������������������������������������������������������������������������������325StaticScaffolding����������������������������������������������������������������������������������������������������������������������������������������������329 H2Console��������������������������������������������������������������������������������������������������������������������������������345CreatingDomainRelationships������������������������������������������������������������������������������������������������347Summary�����������������������������������������������������������������������������������������������������������������������������������354■■Chapter8:PlaywithJavaandScala�����������������������������������������������������������������������������355FeaturesofPlay2��������������������������������������������������������������������������������������������������������������������356MVCinPlay2����������������������������������������������������������������������������������������������������������������������������356 Router����������������������������������������������������������������������������������������������������������������������������������������������������������������357Controller�����������������������������������������������������������������������������������������������������������������������������������������������������������357Model�����������������������������������������������������������������������������������������������������������������������������������������������������������������358View�������������������������������������������������������������������������������������������������������������������������������������������������������������������358 GettingStartedwithPlay����������������������������������������������������������������������������������������������������������358 HelloWorldJavaApplicationwithPlay��������������������������������������������������������������������������������������������������������������360HelloworldScalaApplicationwithPlay2���������������������������������������������������������������������������������������������������������370 ABasicCRUDPlay2JavaApplication���������������������������������������������������������������������������������������373 DefiningtheRoutes�������������������������������������������������������������������������������������������������������������������������������������������373CreatingtheControllerandActions�������������������������������������������������������������������������������������������������������������������374CreatingtheModel��������������������������������������������������������������������������������������������������������������������������������������������375TheFormandtheViewTemplate����������������������������������������������������������������������������������������������������������������������376essingtheDatabase������������������������������������������������������������������������������������������������������������������������������������379DeletingBooks���������������������������������������������������������������������������������������������������������������������������������������������������382 Summary�����������������������������������������������������������������������������������������������������������������������������������382■■AppendixA:IntroductiontoJava����������������������������������������������������������������������������������383 ClassesandObjects������������������������������������������������������������������������������������������������������������������383Variables������������������������������������������������������������������������������������������������������������������������������������384 InstanceMembers���������������������������������������������������������������������������������������������������������������������������������������������384StaticMembers�������������������������������������������������������������������������������������������������������������������������������������������������385 Contentsxiii MethodOverloading������������������������������������������������������������������������������������������������������������������386Arrays����������������������������������������������������������������������������������������������������������������������������������������386Constructors������������������������������������������������������������������������������������������������������������������������������387Encapsulation����������������������������������������������������������������������������������������������������������������������������389Inheritance��������������������������������������������������������������������������������������������������������������������������������389ConstructorChaining�����������������������������������������������������������������������������������������������������������������391Polymorphism���������������������������������������������������������������������������������������������������������������������������393Summary�����������������������������������������������������������������������������������������������������������������������������������398■■AppendixB:IntroductiontoGroovy�������������������������������������������������������������������������������399GettingStarted��������������������������������������������������������������������������������������������������������������������������399 GroovyShell��������������������������������������������������������������������������������������������������������������������������������������������������������401GroovyConsole���������������������������������������������������������������������������������������������������������������������������������������������������402 GStrings�������������������������������������������������������������������������������������������������������������������������������������405 Single-LineStrings��������������������������������������������������������������������������������������������������������������������������������������������405MultilineStrings������������������������������������������������������������������������������������������������������������������������������������������������406SlashyStrings����������������������������������������������������������������������������������������������������������������������������������������������������407MultilineSlashyStrings�������������������������������������������������������������������������������������������������������������������������������������407DollarSlashyStrings�����������������������������������������������������������������������������������������������������������������������������������������408 CollectiveDatatypes������������������������������������������������������������������������������������������������������������������409 Arrays����������������������������������������������������������������������������������������������������������������������������������������������������������������410Lists�������������������������������������������������������������������������������������������������������������������������������������������������������������������410Maps������������������������������������������������������������������������������������������������������������������������������������������������������������������411Ranges���������������������������������������������������������������������������������������������������������������������������������������������������������������412Sets�������������������������������������������������������������������������������������������������������������������������������������������������������������������414 Methods������������������������������������������������������������������������������������������������������������������������������������414Closures������������������������������������������������������������������������������������������������������������������������������������415 UnderstandingClosures������������������������������������������������������������������������������������������������������������������������������������415ImplicitVariables�����������������������������������������������������������������������������������������������������������������������������������������������417ExplicitDeclarationofClosure���������������������������������������������������������������������������������������������������������������������������418ReusingtheMethodasaClosure����������������������������������������������������������������������������������������������������������������������418PassingaClosureasaParameter���������������������������������������������������������������������������������������������������������������������419 xivContents SpecializedOperators���������������������������������������������������������������������������������������������������������������419 SpreadOperator������������������������������������������������������������������������������������������������������������������������������������������������419ElvisOperator����������������������������������������������������������������������������������������������������������������������������������������������������419SafeNavigation/DereferenceOperator��������������������������������������������������������������������������������������������������������������420FieldOperator����������������������������������������������������������������������������������������������������������������������������������������������������421MethodClosureOperator�����������������������������������������������������������������������������������������������������������������������������������421DiamondOperator���������������������������������������������������������������������������������������������������������������������������������������������422 Summary�����������������������������������������������������������������������������������������������������������������������������������422■■AppendixC:IntroductiontoScala���������������������������������������������������������������������������������423 GettingStartedwithScala��������������������������������������������������������������������������������������������������������423 UsingtheInteractiveInterpreter������������������������������������������������������������������������������������������������������������������������423ExecutingScalaCodeasaScript����������������������������������������������������������������������������������������������������������������������424CompilingScalaCode����������������������������������������������������������������������������������������������������������������������������������������424 Variables������������������������������������������������������������������������������������������������������������������������������������426Collections���������������������������������������������������������������������������������������������������������������������������������426 Lists�������������������������������������������������������������������������������������������������������������������������������������������������������������������427Sets�������������������������������������������������������������������������������������������������������������������������������������������������������������������428Maps������������������������������������������������������������������������������������������������������������������������������������������������������������������428 Classes��������������������������������������������������������������������������������������������������������������������������������������429 ExtendingaClass����������������������������������������������������������������������������������������������������������������������������������������������429 Traits������������������������������������������������������������������������������������������������������������������������������������������431SingletonObjects����������������������������������������������������������������������������������������������������������������������432Summary�����������������������������������������������������������������������������������������������������������������������������������433 Index���������������������������������������������������������������������������������������������������������������������������������435 AbouttheAuthor VishalLaykaisthechieftechnologyofficerofStarProtocol.Heisinvolvedinthearchitecture,design,andimplementationofdistributedbusinesssystems,andhisfocusisonconsultingandtrainingwiththeJVMlanguages.HislanguageproficienciesincludeJava,Groovy,Scala,andHaskell.VishalisalsotheleadauthorofBeginningGroovy,Grails,andGriffon(Apress,2012).Whenheneedsabreakfromtechnology,Vishalreadseclecticallyfromcalculustostarformation. xv        AbouttheTechnicalReviewer BorisMinkinisaseniortechnicalarchitectatamajorfinancialcorporation.Hehasmorethan20yearsofexperienceworkinginvariousareasofinformationtechnologyandfinancialservices.Borisobtainedhismaster’sdegreeininformationsystemsatStevensInstituteofTechnologyinNewJersey.Hisprofessionalinterestsareintechnology,service-orientedarchitecture,enterpriseapplicationarchitectureanddevelopment,puting,distributedcaching,Java,andgridandputing.YoucancontactBorisatbm@. xvii        Introduction ThisbookisforalargecrosssectionofmodernJavawebdevelopers,withvariouslevelsofexperience. LearningtheJavaprogramminglanguageisanoblecause,butlearningmerelytheJavalanguageisnotenoughintherealworld.JavadevelopershavetolearnJavaEE,acollectionofrelatedserver-sidetechnologies,toputtheirJavaskillstoanyrealuse. ButlearningJavaEEisnotenougheither.TheJavalanguagealongwithJavaEEmaysufficetodevelopwebapplicationsforprojectsintheanization,asameanstoreusability,butthediverselandscapeofJavaontheWebispermeatedwithseveralwebframeworks,suchasSpringWebMVC,thatmakedevelopmentmucheasier;thus,aJavawebdeveloperhastohavetheknowledgeofthesewebframeworks. Butthisisnotenoughstill.Intheveryfirstlineofthisintroduction,ImentionedthatthisbookisforamodernJavawebdeveloper.ModernJavaismorethanjustalanguage;itisnowafullyoptimizedplatformbecauseseveralotherlanguagessuchasGroovyandScala,calledtheJVMlanguages,nowrunontheJavaVirtualMachine(JVM).AllsuchJVMlanguages,especiallyGroovy,haveacloseassociationwithJava,andyoueacrosswebapplicationsbeforelongwhereJavaandtheseotherJVMlanguagesworkintandem.ThemostambitiousprojectswillrequireyoutobuildwebapplicationsusingtheseJVMlanguages. ThisbookaddressesalltheneedsofamodernJavawebdeveloper.ItisdesignedforbeginnersuptointermediatedevelopersandexplainsthespecificsofJavaontheWeb.Forexample,thisbookisperfectfordeveloperswhoareawareoftechnologieslikeMVCbutdonotyetunderstandhowandwhytheyhavechangedthewaywebapplicationsarebuilt. ThisbookisalsofordeveloperswhowanttolearnframeworksotherthanJSF2(whichisbundledwithJavaEE).Thisbookcoversfourtypesofwebframeworks:requestbased,ponentbased,rapid,andreactive.Amongthesefourtypes,thebookcoversfiveprovenwebframeworks:Struts2,SpringWebMVC,JSF2,Grails2,andPlay2. Inaddition,thisbookisfordeveloperswhohavenoexperienceintheJava,Groovy,andScalaprogramminglanguagesbutwhoyearntocreatewebapplications.Thisbookprovidestheessentialsofthesethreelanguagesintheappendixes. xix xx Introduction Insteadofsimplypronouncingonewebframeworkthebest,LearnJavaforWebDevelopmentshowsthestrengthsofthemostpopularwebframeworksbymeansofareal-worldbookstoreapplication.Developingpleterealapplicationnecessitatesaseamlesscollaborationofdynamicfunctionalities,andthecodeforbuildingponentsiscontrivedandtooinvolved.Insteadoffocusingondevelopingsuchmovingparts,thisbookconfinesitsattentiononleveragingthestrengthsofeachwebframework. HowtheBookIsStructured Thebookconsistsofeightchapters,whichI’lldescribenext,plusthethreepreviouslymentionedappendixesthatintroducetheJava,Groovy,andScalalanguages. Chapter1:IntroducingJavaWebDevelopment Chapter1explainsthemainobjectivethatshapesthisbookandhighlightswhatappearsinthesubsequentchapters.ThischapterbeginswithadiscussionofasignificantchangeintheJavalandscape,itsimplication,andwhatJavaexactlymeanstoday.ThechapterthendiscussesthethreekeyplayersthatjoinforcesinbuildingmodernJavawebapplications:theJVMlanguages,JavaEE,andtheJavawebframeworks. ThischapterintroducesthekeyfeaturesofamodernJavawebapplicationsuchasAjaxandREST,WebSocketforreal-timewebapplication,theTypesafestackforareactivewebapplication,andclient-sideMVCframeworksforresponsiveandsingle-pagewebapplications.Finally,thechapterintroducessomeimportantaspectsofmodernwebdevelopmentthatarebeyondthescopeofthisbook,suchasJavainformationretrievalontheWeb,andbrieflyintroducestheponentofWeb3.0,whichisstillanopensubjectofresearch,theSemanticWeb. Chapter2:BuildingWebApplicationsUsingServletsandJSP Chapter2beginswithadiscussionoftheevolutionandarchitectureofwebapplications.ThechapterthenhighlightshowtousethestandardwebAPI.ThefirstpassatthesampleapplicationusesonlyservletsandJSP.ThenthechaptershowsyouhowtobuildthesameapplicationasaModel2application. Chapter3:BestPracticesinJavaEEWebDevelopment Chapter3examinesthechainofcausalitythatleadstotheneedforfollowingbestpractices.ThechapterexplainstheneedtoevolveprojectsandintroducesExpressionLanguageandJSTL.ThechapterthendiscussestheJavaEEwebtierpatterns. Chapter4:BuildingaWebApplicationUsingStruts2 InChapter4,you’lllearnaboutStruts2.Notaspopularasitusedtobe,Struts2isintroducedinthisbookfordeveloperswhohavetomaintainlegacyapplications.ThischapterfirstintroducesthekeyponentsofStruts2.ThenyouwilllearntodevelopyourfirstapplicationusingStruts2andMaven4.Movingforward,youwilllearntodevelopthebookstoreapplicationandintegratewithTiles3. Introductionxxi Chapter5:BuildingJavaWebApplicationswithSpringWebMVC Chapter5explainsthreekeyobjectivesoftheSpringFramework:loosecouplingusingdependencyinjection,dealingwithcross-cuttingconcernsusingAOP,andremovingboilerplatecodeusingSpringtemplates.ElucidatinghowSpring3works,thechapterintroducestheSpringWebMVCarchitecture.ThenyouwilllearntobuildyourfirstwebapplicationusingSpring3WebMVC.Thischapteralsoshowsyouhowtobuildthebookstoreapplication.YouwilllearntousethelatestversionoftheSpringSourcetoolsuite. Chapter6:Component-BasedWebDevelopmentUsingJSF Chapter6introducesyoutoponent-basedframeworkcalledJSF2thatisbundledwithJavaEE.Afteryouhavefamiliarizedyourselfwiththerequest-basedframeworkpresentedinChapter4andChapter5,understandingJSF2willbemucheasier.ThischaptershowsyouhowJSF2representsaparadigmshiftinwebdevelopmentandintroducesyoutoponentsoftheJSF2architecture.Afteryouhaveafirmgraspoftheponents,thischaptershowsyouhowtodevelopyourfirstJSF2application,andalongwiththisyouwilllearnthelife-cyclephasesofaJSF2application.ThenthechaptershowsyouhowtointegrateJSF2withtheSpringFrameworksothatyoucanessthedatabaseviaSpringtemplatesfromtheJSF2weblayer.Finally,thechaptershowsyouhowtodevelopthebookstoreapplication. Chapter7:RapidWebDevelopmentwithGrails Grailsisarapidapplicationdevelopmentframeworkthatletsyoucreatewebapplicationsinrecordtime.Chapter7introducesyoutotwotechniquesofgeneratingwebapplicationswithGrails:staticanddynamicscaffolding.Thechapterthentakesyouthroughthecodegeneratedandexplainsstep-by-stephowthecodeworks.Havingpresentedthecodegenerated,thischaptershowsyouhowtodevelopthebookstoreapplicationwithGrails2.Thischapteralsocoversunittesting,anoft-neglectedtaskinapplicationdevelopment.ThischaptershowsyouhowtobuildtestsforyourwebapplicationsusingtheJUnittestingframework.Thenthischaptershowsyouhowtousethein-memorydatabaseH2.Inthischapter,youwillalsolearntousethelatestversionoftheGroovy-Grailstoolsuite. Chapter8:PlaywithJavaandScala Chapter8introducesthekeywebplayeroftheTypesafestack,thePlay2framework,andexplainshowtheTypesafestackprovidesanalternativetoJavaEEtobuildJava-andScala-basedapplications.FirstyouwilllearntodevelopaJava-basedwebapplicationusingPlay2.ThenyouwilllearntodevelopaScala-basedwebapplicationusingPlay2.Subsequently,thischaptershowshowtousethemodelandessadatabaseinPlay2.

标签: #视频文件 #发送到 #文件 #文件 #苹果 #怎么改 #优盘 #画质