计算机专业文献翻译用 Tomcat 和 Eclipse开发 Web 应用程序.docx
《计算机专业文献翻译用 Tomcat 和 Eclipse开发 Web 应用程序.docx》由会员分享,可在线阅读,更多相关《计算机专业文献翻译用 Tomcat 和 Eclipse开发 Web 应用程序.docx(20页珍藏版)》请在冰豆网上搜索。
![计算机专业文献翻译用 Tomcat 和 Eclipse开发 Web 应用程序.docx](https://file1.bdocx.com/fileroot1/2022-10/12/c6ec3897-cdc7-42ea-8aee-c278f0ed436e/c6ec3897-cdc7-42ea-8aee-c278f0ed436e1.gif)
计算机专业文献翻译用Tomcat和Eclipse开发Web应用程序
DevelopingWebapplicationswithTomcatandEclipse
Requiredcomponents
TheEclipseV3.2Callistointegrateddevelopmentenvironment(IDE)includestoolsfordoingWebdevelopmentandintegratingwithservers.So,asidefromthesoftwaredevelopmentkit(SDK),youneedonlyEclipseandApacheTomcatinstalled.Theversionsfeaturedinthisarticlearelistedbelow.
Table1.Componentsandversionsused
Component
Versionusedinthisarticle
EclipsePlatform
3.2.2
JavaEE5SDK
1.5.0_09
ApacheTomcat
5.5.20
TheEclipseIDEisanopensourceIDEusedasthedevelopmentenvironmentforyourJava™ServerPages(JSPs)andJavafiles.WiththeWebandJava2Platform,EnterpriseEdition(J2EE)Developmenttoolsinstalled,EclipseisgreattoolforcreatingHTML,JSPs,andservlets.
YouneedtheJavaSDKtorunservletsonyourmachine.Finally,ApacheTomcatisanopensourceWebandservletcontainer,usedintheofficialreferenceimplementationsforJavaServletandJavaServerPages.
Installation
InstallationofEclipseandTomcatissimilar—bothareextractedfromthearchivefileformatintoafolderonyourharddisk.Ifyoueverwanttouninstalleither,it'sassimpleasdeletingthedirectoryinwhichyouextractedthefiles.
InstallEclipse
ToinstalltheEclipseIDE,unpackthecompressed(.zipor.tar.gz)fileyoudownloadedfromEclipse,thenmovetheunpackedfolderintoaconvenientlocation.ItrytoinstallitinalocationthatfollowstheconventionsofwhateveroperatingsystemI'musing.IfI'minstallingEclipseonaMacintosh,IputtheEclipsefolderintheApplicationsfolder.IfI'musingMicrosoft™Windows™,IputtheunpackedfolderintotheC:
\ProgramFilesdirectory.
Onceyou'vedownloadedandinstalledEclipse,startitup.BeforeyoucancreateaWebproject,youneedtoinstalltheJ2EEandWebDevelopmentplug-ins.Fortunately,it'seasytoinstalltheplug-inusingtheCallistoDiscoverySite.
InstalltheWebtools
WiththeEclipseIDErunning,selectHelp>SoftwareUpdates>FindandInstall.ThisoptionletsyoudownloadandinstalltheWebtoolswithoutgoingtoaWebsite.
SelectSearchforNewFeaturestoInstall,asshownbelow,thenclickNext.
Figure1.Install/Updatewindow
SelectCallistoDiscoverySite,asshownbelow,thenclickNext.
Figure2.SelecttheCallistoDiscoverySite
UnderCallistoDiscoverySite,checktheWebandJ2EEDevelopmentbox.Thewizardimmediatelywarnsyouthatyou'remissingdependencies.ClickSelectRequired,andthesewarningsshoulddisappear.SomeorallofthecomponentsintheGraphicalEditorsandFrameworksandModelsandModelDevelopmentcategoriesareselected(asshowninFigure3)becausethey'rerequiredfortheinstallationoftheWebandJ2EEplug-ins.
Figure3.Selectfeaturesforinstallation
ClickNexttocontinue,andlicenseagreementsappearforeachfeatureyou'veselected.Ifyouagreewiththelicenses,acceptthemandfollowthewizardthroughtherestoftheprocess.WhentheIDEisfinishedinstallingtheplug-ins,itasksyoutorestartEclipseinorderforthechangestotakeeffect.BesureyourestarttheIDEbeforecontinuing.
AfteryourestarttheIDE,thenewfeaturesareavailabletobegindevelopingdynamicWebprojects.
InstallTomcat
ToinstallApacheTomcat,extractthefilesfromthedownloadedarchiveandplacethemintoadirectory.IputtheminmyC:
\appsdirectorytomakethemeasytolocatelater.That'sitfornow;useEclipseasshownlatertostartTomcat.
CreateanewWebproject
FromtheEclipseIDE,selectFile>New>Projecttoviewtheprojectwizards.TypeWebintheWizardsbox,andtheNewProjectwindowfiltersthewizardstoshowtheonesthatmatch.Thisisaneasywaytolocatethewizardyouwantinsteadofgoingthrougheachitem.
ChooseDynamicWebProjectfromthelist.YouusetheStandardWebProjectWizardtomakestaticHTMLWebprojects.YoucantechnicallyuseTomcattorunstaticWebsites,althoughaWebserversuchasApacheWebServermaybeabetterchoiceforstaticcontent.Webserversbuiltspecificallyforservingupstaticpagestendtohavelessoverheadandaretunedforthatpurpose.
Targetaruntime
UnderTargetRuntime,yousee,asshowninFigure4,becauseyouhaven'tcreatedaruntimeyetforApacheTomcat.ClickNewtoopentheNewTargetRuntimeWizard.SelectApacheTomcatV5.5fromtheApachefolder,asshowninFigure5,thenclickNext.
Figure4.CreateanewdynamicWebproject
Figure5.Createanewserverruntime
Nowyouhavetheopportunitytonameyourruntime,althoughthedefaultnameApacheTomcatV5.5isfine.ClickBrowsetolocatethebasefolderforyourApacheTomcatconfiguration(mineisC:
\apps\apache-tomcat-5.5.20,asshowninFigure6).IrecommendleavingtheIBM®JavaRuntimeEnvironment(JRE)versionthesameas