用 Tomcat 和 Eclipse开发 Web 应用程序英文原文及中文翻译Word文件下载.docx
- 文档编号:6557630
- 上传时间:2023-05-06
- 格式:DOCX
- 页数:22
- 大小:430.23KB
用 Tomcat 和 Eclipse开发 Web 应用程序英文原文及中文翻译Word文件下载.docx
《用 Tomcat 和 Eclipse开发 Web 应用程序英文原文及中文翻译Word文件下载.docx》由会员分享,可在线阅读,更多相关《用 Tomcat 和 Eclipse开发 Web 应用程序英文原文及中文翻译Word文件下载.docx(22页珍藏版)》请在冰点文库上搜索。
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<
None>
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)versionthesameastheworkbenchdefaultJRE,unlessyouhaveaspecificreasontochangeit.Onceyou'
veenteredavaliddirectory,clickFinishtocreatetheruntimeconfiguration.
Figure6.Definetheserverlocation
You'
reaskedifyouwanttoswitchtotheJ2EEPerspective.IalwaysansweryesbecausethatperspectiveincludesviewsliketheServersview,whichhelptostartandstopTomcatlater.YoucanalwaysopentheServersviewbyselectingWindow>
ShowView.
Addtheserver
IntheServersviewisaviewthatcontainsnothing.ThisviewisforapplicationandWebservers;
itletsyoucontrolthemandmonitortheirstatus.TocontrolTomcatdirectlyfromthecomfortoftheIDE,addareferencetoTomcatbyselectingNew>
Serverfromthecontext-sensitivemenu.TheNewServerwizard,asshowninFigure7,willdefaulttotheApacheTomcatV5.5runtimeyoujustcreated.
Figure7.Defineanewserver
ClickNext.You'
reaskedwhetheryouwanttoaddprojectstotheserver.Selecttheprojectyoucreatedintheprevioussteps,thenclickAdd.
Figure8.Addtheprojectstotheserver
ClickFinishtoclosethewizard.NowtheServersviewcontainstheTomcatV5.5Serverwiththeprojectunderit.
Figure9.TheTomcatserverintheServersview
Createasamplepage
TheeasiestwaytotestyournewdynamicWebprojectandTomcatserverintegrationistocreateasimpleJSPanddeployittoTomcat.YoucancreatethenewJSPfilebyselectingFile>
Other,oryoucanusethecontext-sensitivemenubyright-clickingtheprojectnameintheProjectExplorerviewandselectingNew>
JSP.
MakesuretheparentfolderisWebContentandnamethefileindex.jsp.ClickFinishtocreatethepageusingthedefaulttemplate.IfyouclickNext,youcanchoosedifferenttemplatestouse(suchasHTMLorXHTML)forthenewpage.Thedefaultsarefineforthistest.
Thepagecodeshownbelowdisplaysasimpledatesoyoucanseeitworking.
Listing1.Contentsofindex.jsp
<
%@pagelanguage="
java"
contentType="
text/html;
charset=ISO-8859-1"
pageEncoding="
ISO-8859-1"
%>
!
DOCTYPEhtmlPUBLIC"
-//W3C//DTDHTML4.01Transitional//EN"
"
http:
//www.w3.org/TR/html4/loose.dtd"
>
html>
head>
metahttp-equiv="
Content-Type"
content="
title>
MyTitle<
/title>
/head>
body>
%java.util.Dated=newjava.util.Date();
%>
h1>
Today'
sdateis<
%=d.toString()%>
andthisjsppageworked!
/h1>
/body>
/html>
Deploythepage
Nowthatthetestpageiscomplete,useEclipsetoredeployittoApacheTomcat.IntheServersview,noticethatStateissettoRepublish.Thatisbecausechangeshavebeenmadesincetheprojectwaslastdeployedtotheserver.Right-clicktheserverandselectPublishfromthemenu.ThestatechangestoSynchronizedoncetheprojecthasbeendeployedtotheserver.
Withtheprojectsuccessfullydeployedandtheserverstarted,openabrowserandnavigatetohttp:
//localhost:
8080/[ProjectName]/(where[ProjectName]isthenameofthedynamicWebprojectyoucreated).ThenewWebpageyoucreatedappears,andthedateshouldbecurrent.Ifyourefreshthepage,thedatechanges.
Figure10.Outputofindex.jspinabrowser
HelloWorldservlet
YoucanaddJavaservletstoyourprojectanddeploythem.Tocreateaquickservletyoucanusefortestingpurposes,usetheServletWizardbyright-clickingyourdynamicWebprojectintheProjectExplorerviewandselectingNew>
Other.UndertheWebfolder,selectServlet,thenclickNext.
Addthepackagenamecom.example.servletsnexttoJavaPackageandaddHelloServletnexttoClassname.ClickFinish.Thisisanexample,sothedefaultsarefine.TheEclipseIDEgeneratesaservletclassforyou.Towatchthetestservletinaction,addalineinthedoGet()methodtoprintamessagetotheResponseWriter.Theservletclassshouldlookliketheoneshownbelow.
Listing2.ContentsofHelloServlet.java
packagecom.example.servlets;
importjava.io.IOException;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
/**
*ServletimplementationclassforServlet:
HelloServlet
*
*/
publicclassHelloServletextendsjavax.servlet.http.HttpServlet
implementsjavax.servlet.Servlet{
/*(non-Java-doc)
*@seejavax.servlet.http.HttpServlet#HttpServlet()
publicHelloServlet(){
super();
}
*@seejavax.servlet.http.HttpServlet#doGet(HttpServletRequestrequest,
HttpServletResponseresponse)
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
response.getWriter().write("
Hello,world!
"
);
*@seejavax.servlet.http.HttpServlet#doPost(HttpServletRequestrequest,
protectedvoiddoPost(HttpServletRequestrequest,HttpS
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Tomcat Eclipse开发 Web 应用程序英文原文及中文翻译 Eclipse 开发 应用程序 英文 原文 中文翻译
链接地址:https://www.bingdoc.com/p-6557630.html