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

Addison wesley servlets and javaserver pages the J2EE technology web tier sep 2003 ISBN 0321136497

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 (1.68 MB, 2 trang )

FinishingtheSite
Beforemovingon,thereareafewbitsandpiecesofthesitethatneedtobe
addressed.Thebulkofthesiteconsistsofthecustomcomponentspreviously
addressedbythischapter.Allofthecustomcomponentsrequiredcodingfrom
scratch.Nowweshalladdressseveralcomplementarycomponentsthatwere
demonstratedinpreviouschapters.Allthecomponentswillberelativelysimple
toimplement;insteadofcodingfromscratch,wewillsimplydeploypreviously
explainedcodelistings.
Thelistofthingstoimplementisasfollows:site-wideerrorhandling,security,
linktracking,caching,compression,andthesite'shiddenEasteregg.Eachofthe
componentswascompletelycoveredinpreviouschapters,buteachcomponent
isbrieflyrehashedinthefollowingsectionsasitisinstalledforusewiththe
booksupportsite.
Site-WideErrorHandling
Allofthecodepreviouslyprovidedforthebooksupportsiteusespropererror
handling;however,anerrorcanstillbethrown(althoughitprobablyneverwill)
bytheWebApplication.Shouldthishappen,thecontainerwillhavetohandle
theerror.Normally,aswithTomcat,astacktraceisprintedanddisplayedina
developer-friendlyfashion,meaningacrypticpageisshowntoauser.To
preventthisfromhappening,weneedtocreateaWebApplicationerrorpage.
You'llrecallinChapter4thatthistopicwasdiscussedatlength.Theerrorpage
needstobenothingmorethanasimpleJSPorServletthatisregisteredvia
web.xml.
Listing15-35showsasimpleerrorpage.
Listing15-35.error.jsp

[Viewfullwidth]

Oops!


Anerrorhasoccurred.Informationabouttheproblemhasbeen
loggedandwillbehandledbyadministratorsassoonaspossible.If


youwouldliketosendfurtherinformation,pleasecontact.com">support</a>.




Thepagedoesn'tdoanythingfancy.Itapologeticallyinformsauserthatthesite
hasfailedtofunctioncorrectly.Additionally,anemailaddressisprovidedin
casetheuserwishestocommunicatefurtherabouttheproblem.
Saveerror.jspintherootdirectoryofthejspbook_siteWebApplication.
Deploythepageasthesite'sdefaulterrorpagebyaddingListing15-36to
web.xml.
Listing15-36.Settingerror.jspastheSite'sDefaultErrorPage

<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.jsp</location>
</error-page>

ReloadtheWebApplicationforthechangestotakeeffect.NowwehaveafailsafecountertoTomcat'sdisplayingacrypticstacktracetouse.Althoughit
shouldneverhappen,planfortheworst.Youcantestthepagebybrowsing
http://127.0.0.1/jspbook_site/error.jsp.Thepageprovidesapoliteerror
messageandisrenderedwiththesite'simplicitheaderandfooter.Figure15-18
providesabrowserrenderingoftheresultsinEnglish.
Figure15-18.BrowserRenderingofthePoliteErrorPage



×