




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
原文一:
JavaProgrammingwithOracleJDBC:Performance
Performanceisusuallyconsideredanissueattheendofadevelopmentcyclewhenitshouldreallybeconsideredfromthestart.Often,ataskcalled"performancetuning"isdoneafterthecodingiscomplete,andtheenduserofaprogramcomplainsabouthowlongittakestheprogramtocompleteaparticulartask.Thenetresultofwaitinguntiltheendofthedevelopmentcycletoconsiderperformanceincludestheexpenseoftheadditionaltimerequiredtorecodeaprogramtoimproveitsperformance.It'smyopinionthatperformanceissomethingthatisbestconsideredatthestartofaproject.
WhenitcomestoperformanceissuesconcerningJDBCprogrammingtherearetwomajorfactorstoconsider.ThefirstistheperformanceofthedatabasestructureandtheSQLstatementsusedagainstit.ThesecondistherelativeefficiencyofthedifferentwaysyoucanusetheJDBCinterfacestomanipulateadatabase.
Intermsofthedatabase'sefficiency,youcanusetheEXPLAINPLANfacilitytoexplainhowthedatabase'soptimizerplanstoexecuteyourSQLstatements.Armedwiththisknowledge,youmaydeterminethatadditionalindexesareneeded,orthatyourequireanalternativemeansofselectingthedatayoudesire.
Ontheotherhand,whenitcomestousingJDBC,youneedtoknowaheadoftimetherelativestrengthsandweaknessesofusingauto-commit,SQL92syntax,andaStatementversusaPreparedStatementversusaCallableStatementobject.Inthischapter,we'llexaminetherelativeperformanceofvariousJDBCobjectsusingexampleprogramsthatreporttheamountoftimeittakestoaccomplishagiventask.We'llfirstlookatauto-commit.Next,we'lllookattheimpactoftheSQL92syntaxparser.Thenwe'llstartaseriesofcomparisonsoftheStatementobjectversusthePreparedStatementobjectversustheCallableStatementobject.Atthesametimewe'llalsoexaminetheperformanceoftheOCIversustheThindriverineachsituationtoseeif,asOracle'sclaims,thereisasignificantenoughperformancegainwiththeOCIdriverthatyoushoulduseitinsteadoftheThindriver.Forthemostpart,ourdiscussionswillbebasedontimingdatafor1,000insertsintothetestperformancetableTESTXXXPERF.Thereareseparateprogramsforperformingthese1,000insertsusingtheOCIdriverandtheThindriver.
Theperformancetestprogramsthemselvesareverysimpleandareavailableonlinewiththerestoftheexamplesinthisbook.However,forbrevity,I'llnotshowthecodefortheexamplesinthischapter.I'llonlytalkaboutthem.Althoughtheactualtimingvalueschangefromsystemtosystem,theirrelativevalues,orratiosfromonesystemtoanother,remainconsistent.ThetimingsusedinthischapterweregatheredusingWindows2000.Usingobjectivedatafromtheseprogramsallowsustocometofactualconclusionsonwhichfactorsimproveperformance,ratherthanrelyingonhearsay.
I'msureyou'llbesurprisedattherealityofperformancefortheseobjects,andIhopeyou'llusethisknowledgetoyouradvantage.Let'sgetstartedwithalookatthetestingframeworkusedinthischapter.
ATestingFramework
Forthemostpart,thetestprogramsinthischapterreportthetimingsforinsertingdataintoatable.IpickedanINSERTstatementbecauseiteliminatestheperformancegainofthedatabaseblockbuffersthatmayskewtimingsforanUPDATE,DELETE,orSELECT.
Thetesttableusedintheexampleprogramsinthischapterisasimplerelationaltable.IwantedittohaveaNUMBER,asmallVARCHAR2,alargeVARCHAR2,andaDATEcolumn.TableTESTXXXPERFisdefinedas:
createtableTestXXXPerf(
idnumber,
codevarchar2(30),
descrvarchar2(80),
insert_uservarchar2(30),
insert_datedate)
tablespaceuserspctfree20
storage(initial1Mnext1Mpctincrease0);
altertableTestXXXPerf
addconstraintTestXXXPerf_Pk
primarykey(id)
usingindex
tablespaceuserspctfree20
storage(initial1Mnext1Mpctincrease0);
Theinitialextentsizeusedforthetablemakesitunlikelythatthedatabasewillneedtotakethetimetoallocateanotherextentduringtheexecutionofoneofthetestprograms.Therefore,extentallocationwillnotimpactthetimings.Giventhisbackground,youshouldhaveacontexttounderstandwhatisdoneineachsectionbyeachtestprogram.
Auto-Commit
Bydefault,JDBC'sauto-commitfeatureison,whichmeansthateachSQLstatementiscommittedasitisexecuted.IfmorethanoneSQLstatementisexecutedbyyourprogram,thenasmallperformanceincreasecanbeachievedbyturningoffauto-commit.
Let'stakealookatsomenumbers.
Table19-1
showstheaveragetime,inmilliseconds,neededtoinsert1,000rowsintotheTESTXXXPERFtableusingaStatementobject.Thetimingsrepresenttheaveragefromthreerunsoftheprogram.Bothdriversexperienceapproximatelyaone-secondlossasoverheadforcommittingbetweeneachSQLstatement.Whenyoudividethatonesecondby1,000inserts,youcanseethatturningoffauto-commitsavesapproximately0.001seconds(1millisecond)perSQLstatement.Whilethat'snotinterestingenoughtowritehomeabout,itdoesdemonstratehowauto-commitcanimpactperformance.
Table19-1:Auto-committimings(inmilliseconds)
Auto-commit
OCI
Thin
On
3,712
3,675
Off
2,613
2,594
Clearly,it'smoreimportanttoturnoffauto-commitformanagingmultisteptransactionsthanforgainingperformance.Butonaheavilyloadedsystemwheremanyusersarecommittingtransactions,theamountoftimeittakestoperformcommitscanbecomequitesignificant.Somyrecommendationistoturnoffauto-commitandmanageyourtransactionsmanually.Therestofthetestsinthischapterareperformedwithauto-committurnedoff.
SQL92TokenParsing
Likeauto-commit,SQL92escapesyntaxtokenparsingisonbydefault.Incaseyoudon'trecall,SQL92tokenparsingallowsyoutoembedSQL92escapesyntaxinyourSQLstatements(see"OracleandSQL92EscapeSyntax"inChapter9).Thesestandards-basedsnippetsofsyntaxareparsedbyaJDBCdrivertransformingtheSQLstatementintoitsnativesyntaxforthetargetdatabase.SQL92escapesyntaxallowsyoutomakeyourcodemoreportable--butdoesthisportabilitycomewithacostintermsofperformance?
Table19-2showsthenumberofmillisecondsneededtoinsert1,000rowsintotheTESTXXXPERFtable.TimingsareshownwiththeSQL92escapesyntaxparseronandoffforboththeOCIandThindrivers.Asbefore,thesetimingsrepresenttheresultofthreeprogramrunsaveragedtogether.
Table19-2:SQL92tokenparsertimings(inmilliseconds)
SQL92parser
OCI
Thin
On
2,567
2,514
Off
2,744
2,550
NoticefromTable19-2thatwiththeOCIdriverwelose177millisecondswhenescapesyntaxparsingisturnedoff,andweloseonly37millisecondswhentheparseristurnedoffwiththeThindriver.Theseresultsaretheoppositeofwhatyoumightintuitivelyexpect.ItappearsthatbothdrivershavebeenoptimizedforSQL92parsing,soyoushouldleaveitonforbestperformance.
NowthatyouknowyouneverhavetoworryaboutturningtheSQL92parseroff,let'smoveontosomethingthathassomepotentialforprovidingasubstantialperformanceimprovement.
StatementVersusPreparedStatement
There'sapopularbeliefthatusingaPreparedStatementobjectisfasterthanusingaStatementobject.Afterall,apreparedstatementhastoverifyitsmetadataagainstthedatabaseonlyonce,whileastatementhastodoiteverytime.Sohowcoulditbeanyotherway?Well,thetruthofthematteristhatittakesabout65iterationsofapreparedstatementbeforeitstotaltimeforexecutioncatchesupwithastatement.WhenitcomestowhichSQLstatementobjectperformsbetterundertypicaluse,aStatementoraPreparedStatement,thetruthisthattheStatementobjectyieldsthebestperformance.WhenyouconsiderhowSQLstatementsaretypicallyusedinanapplication--1or2here,maybe10-20(rarelymore)pertransaction--yourealizethataStatementobjectwillperformtheminlesstimethanaPreparedStatementobject.Inthenexttwosections,we'lllookatthisperformanceissuewithrespecttoboththeOCIdriverandtheThindriver.
TheOCIDriver
Table19-3
showsthetimingsinmillisecondsfor1insertand1,000insertsintheTESTXXXPERFtable.TheinsertsaredonefirstusingaStatementobjectandthenaPreparedStatementobject.Ifyoulookattheresultsfor1,000inserts,youmaythinkthatapreparedstatementperformsbetter.Afterall,at1,000inserts,thePreparedStatementobjectisalmosttwiceasfastastheStatementobject,butifyouexamine
Figure19-1
,you'llseeadifferentstory.
Table19-3:OCIdrivertimings(inmilliseconds)
Inserts
Statement
PreparedStatement
1
10
113
1,000
2,804
1,412
Figure19-1isagraphofthetimingsneededtoinsertvaryingnumbersofrowsusingbothaStatementobjectandaPreparedStatementobject.Thenumberofinsertsbeginsat1andclimbsinintervalsof10uptoamaximumof150inserts.Forthisgraphandforthosethatfollow,thelinesthemselvesarepolynomialtrendlineswithafactorof2.Ichosepolynomiallinesinsteadofstraighttrendlinessoyoucanbetterseeachangeintheperformanceasthenumberofinsertsincreases.Ichoseafactorof2sothelineshaveonlyonecurveinthem.Theimportantthingtonoticeaboutthegraphisthatit'snotuntilabout65insertsthatthePreparedStatementobjectoutperformstheStatementobject.65inserts!Clearly,theStatementobjectismoreefficientundertypicalusewhenusingtheOCIdriver.
Figure19-1
TheThinDriver
IfyouexamineTable19-4(whichshowsthesametimingsasforTable19-3,butfortheThindriver)andFigure19-2(whichshowsthedataincrementally),you'llseethattheThindriverfollowsthesamebehaviorastheOCIdriver.However,sincetheStatementobjectstartsoutperformingbetterthanthePreparedStatementobject,ittakesabout125insertsforthePreparedStatementtooutperformStatement.
Table19-4:Thindrivertimings(inmilliseconds)
Inserts
Statement
PreparedStatement
1
10
113
1,000
2,583
1,739
Figure19-2
WhenyouconsidertypicalSQLstatementusage,evenwiththeThindriver,you'llgetbetterperformanceifyouexecuteyourSQLstatementsusingaStatementobjectinsteadofaPreparedStatementobject.Giventhat,youmayask:whyuseaPreparedStatementatall?ItturnsoutthattherearesomereasonswhyyoumightuseaPreparedStatementobjecttoexecuteSQLstatements.First,thereareseveraltypesofoperationsthatyousimplycan'tperformwithoutPreparedStatementobject.Forexample,youmustuseaPreparedStatementobjectifyouwanttouselargeobjectslikeBLOBsorCLOBsorifyouwishtouseobjectSQL.Essentially,youtradesomelossofperformancefortheaddedfunctionalityofusingtheseobjecttechnologies.AsecondreasontouseaPreparedStatementisitssupportforbatching.
Batching
Asyousawintheprevioussection,PreparedStatementobjectseventuallybecomemoreefficientthantheirStatementcounterpartsafter65-125executionsofthesamestatement.Ifyou'regoingtoexecuteagivenSQLstatementalargenumberoftimes,itmakessensefromaperformancestandpointtouseaPreparedStatementobject.Butifyou'rereallygoingtodothatmanyexecutionsofastatement,orperhapsmorethan50,youshouldconsiderbatching.BatchingismoreefficientbecauseitsendsmultipleSQLstatementstotheserveratonetime.AlthoughJDBCdefinesbatchingcapabilityforStatementobjects,OraclesupportsbatchingonlywhenPrepared-Statementobjectsareused.Thismakessomesense.ASQLstatementinaPreparedStatementobjectisparsedonceandcanbereusedmanytimes.Thisnaturallylendsitselftobatching.
TheOCIDriver
Table19-5listsStatementandbatchedPreparedStatementtimings,inmilliseconds,for1insertandfor1,000inserts.Atthelowend,oneinsert,youtakeasmallperformancehitforsupportingbatching.Atthehighend,1,000inserts,you'vegained75%throughput.
Table19-5:OCIdrivertimings(inmilliseconds)
Inserts
Statement
Batched
1
10
117
1,000
2,804
691
IfyouexamineFigure19-3,atrendlineanalysisoftheStatementobjectversusthebatchedPreparedStatementobject,you'llseethatthistime,thebatchedPrepared-StatementobjectbecomesmoreefficientthantheStatementobjectatabout50inserts.Thisisanimprovementoverthepreparedstatementwithoutbatching.
Figure19-3
WARNING:There'sacatchhere.The8.1.6OCIdriverhasadefectbywhichitdoesnotsupportstandardJavabatching,sothenumbersreportedherewerederivedusingOracle'sproprietarybatching.
Now,let'stakealookatbatchinginconjunctionwiththeThindriver.
TheThinDriver
TheThindriverisevenmoreefficientthantheOCIdriverwhenitcomestousingbatchedpreparedstatements.Table19-6showsthetimingsfortheThindriverusingaStatementobjectversusabatchedPreparedStatementobjectinmillisecondsforthespecifiednumberofinserts.
Table19-6:Thindrivertimings(inmilliseconds)
Inserts
Statement
Batched
1
10
117
1,000
2,583
367
TheThindrivertakesthesameperformancehitonthelowend,oneinsert,butgainsawhopping86%improvementonthehighend.Yes,1,000insertsinlessthanasecond!IfyouexamineFigure19-4,you'llseethatwiththeThindriver,theuseofabatchedPreparedStatementobjectbecomesmoreefficientthanaStatementobjectmorequicklythanwiththeOCIdriver--atabout40inserts.
Figure19-4
IfyouintendtoperformmanyiterationsofthesameSQLstatementagainstadatabase,youshouldconsiderbatchingwithaPreparedStatementobject.
We'vefinishedlookingatimprovingtheperformanceofinserts,updates,anddeletes.Nowlet'sseewhatwecandotosqueakoutalittleperformancewhileselectingdata.
PredefinedSELECTStatements
EverytimeyouexecuteaSELECTstatement,theJDBCdrivermakestworoundtripstothedatabase.Onthefirstroundtrip,itretrievesthemetadataforthecolumnsyouareselecting.Onthesecondroundtrip,itretrievestheactualdatayouselected.Withthisinmind,youcanimprovetheperformanceofaSELECTstatementby50%ifyoupredefinetheSelecstatementbyusingOracle'sdefineColumnType()methodwithanOracleStatementobject(see"DefiningColumns"inChapter9).WhenyoupredefineaSELECTstatement,youprovidetheJDBCdriverwiththecolumnmetadatausingthedefineColumnType()method,obviatingtheneedforthedrivertomakearoundtriptothedatabaseforthatinformation.Hence,forasingletonSELECT,youeliminatehalftheworkwhenyoupredefinethestatement.
Table19-7showsthetimingsinmillisecondsrequiredtoselectasinglerowfromtheTESTXXXPERFtable.Timingsareshownforwhenthecolumntypehasbeenpredefinedandwhenithasnotbeenpredefined.TimingsareshownforboththeOCIandThindrivers.AlthoughthedefineColumnType()methodshowslittleimprovementwitheitherdriverinmytest,onaloadednetwork,you'llseeadifferentiationinthetimingsofabout50%.GivenasituationinwhichyouneedtomakeseveraltightcallstothedatabaseusingaStatement,apredefinedSELECTstatementcansaveyouasignificantamountoftime.
Table19-7:Selecttimings(inmilliseconds)
Driver
Statement
defineColumnType()
OCI
13
10
Thin
13
10
Nowthatwe'velookedatauto-commit,SQL92parsing,preparedstatements,andapredefinedSELECT,let'stakealookattheperformanceofcallablestatements.
CallableStatements
Asyoumayrecall,CallableStatementobjectsareusedtoexecutedatabasestoredprocedures.I'vesavedCallableStatementobjectsuntillast,becausetheyaretheslowestperformersofalltheJDBCSQLexecutioninterfaces.Thismaysoundcounterintuitive,becauseit'scommonlybelievedthatcallingstoredproceduresisfasterthanusingSQL,butthat'ssimplynottrue.GivenasimpleSQLstatement,andastoredprocedurecallthataccomplishesthesametask,thesimpleSQLstatementwillalwaysexecutefaster.Why?Becausewiththestoredprocedure,younotonlyhavethetimeneededtoexecutetheSQLstatementbutalsothetimeneededtodealwiththeoverheadoftheprocedurecallitself.
Table19-8liststherelativetime,inmilliseconds,neededtocallthestoredprocedureTESTXXXPERF$.SETTESTXXXPERF().ThisstoredprocedureinsertsonerowintothetableTESTXXXPERF.TimingsareprovidedforboththeOCIandThindrivers.Noticethatbothdriversareslowerwheninsertingarowthiswaythanwhenusingeitherastatementorabatchedpreparedstatement(refertoTables19-3through19-6).Commonsensewilltellyouwhy.TheSETTESTXXXPERF()procedureinsertsarowintothedatabase.ItdoesexactlythesamethingthattheotherJDBCobjectsdidbutwiththeaddedoverheadofaroundtripforexecutingtheremoteprocedurecall.
Table19-8:Storedprocedurecalltimings(inmilliseconds)
Inserts
OCI
Thin
1
113
117
1,000
1,723
1,752
Storedproceduresdohavetheiruses.IfyouhaveacomplextaskthatrequiresseveralSQLstatementstocomplete,andyouencapsulatethoseSQLstatementsintoastoredprocedurethatyouthencallonlyonce,you'llgetbetterperformancethanifyouexecutedeachSQLstatementseparatelyfromyourprogram.Thisperformancegainistheresultofyourprogramnothavingtomovealltherelateddatabackandforthoverthenetwork,whichisoftentheslowestpartofthedatamanipulationprocess.ThisishowstoredproceduresaresupposedtobeusedwithOracle--notasasubstituteforSQL,butasameanstoperformworkwhereitcanbedonemostefficiently.
OCIVersusThinDrivers
Oracle'sdocumentationstatesthatyoushouldusetheOCIdriverformaximumperformanceandtheThindriverformaximumportability.However,IrecommendusingtheThindriverallthetime.Let'stakealookatsomenumbersfromWindows2000.Table19-9listsallthestatisticswe'vecoveredinthischapter.
Table19-9:OCIversusThindrivertimings(inmilliseconds)
Metric
OCI
Thin
1,000insertswithauto-commit
3,712
3,675
1,000insertswithmanualcommit
2,613
2,594
1insertwithStatement
10
10
1,000insertswithStatement
2,804
2,583
1insertwithPreparedStatement
113
113
1,000insertsbatched
1,482
367
SELECT
10
10
PredefinedSELECT
10
10
1insertwithCallableStatement
113
117
1,000insertswithCallableStatement
1,723
1,752
Totals
12,590
11,231
AsyoucanseefromTable19-9,theThindriverclearlyoutperformstheOCIdriverforeverytypeofoperationexceptexecutionsofCallableStatementobjects.OnaUnixplatform,myexperiencehasbeenthattheCallableStatementnumbersaretiltedevenmoreinfavoroftheOCIdriver.Nonetheless,youcanfeelcompletelycomfortableusingtheThindriverinalmostanysetting.TheThindriverhasbeenwell-tunedbyOracle'sJDBCdevelopmentteamtoperformbetterthanitsOCIcounterpart.
原文二:
ExtendingStruts
Introduction
IhaveseenlotofprojectswherethedevelopersimplementedaproprietaryMVCframework,notbecausetheywantedtodosomethingfundamentallydifferentfromStruts,butbecausetheywerenotawareofhowtoextendStruts.YoucangettotalcontrolbydevelopingyourownMVCframework,butitalsomeansyouhavetocommitalotofresourcestoit,somethingthatmaynotbepossibleinprojectswithtightschedules.
Struts
isnotonlyaverypowerfulframework,butalsoveryextensible.YoucanextendStrutsinthreeways.
PlugIn:CreateyourownPlugInclassifyouwanttoexecutesomebusinesslogicatapplicationstartuporshutdown.
RequestProcessor:CreateyourownRequestProcessorifyouwanttoexecutesomebusinesslogicataparticularpointduringtherequest-processingphase.Forexample,youmightextendRequestProcessortocheckthattheuserisloggedinandhehasoneoftherolestoexecuteaparticularactionbeforeexecutingeveryrequest.
ActionServlet:YoucanextendtheActionServletclassifyouwanttoexecuteyourbusinesslogicateitherapplicationstartuporshutdown,orduringrequestprocessing.ButyoushoulduseitonlyincaseswhereneitherPlugInnorRequestProcessorisabletofulfillyourrequirement.
Inthisarticle,wewilluseasampleStrutsapplicationtodemonstratehowtoextendStrutsusingeachofthesethreeapproaches.Downloadablesamplecodeforeachisavailablebelowinthe
Resources
sectionattheendofthisarticle.TwoofthemostsuccessfulexamplesofStrutsextensionsarethe
StrutsValidation
frameworkandthe
Tiles
framework.
IassumethatyouarealreadyfamiliarwiththeStrutsframeworkandknowhowtocreatesimpleapplicationsusingit.Pleaseseethe
Resources
sectionifyouwanttoknowmoreaboutStruts.
PlugIn
AccordingtotheStrutsdocumentation"Apluginisaconfigurationwrapperforamodule-specificresourceorservicethatneedstobenotifiedaboutapplicationstartupandshutdownevents."WhatthismeansisthatyoucancreateaclassimplementingthePlugIninterfacetodosomethingatapplicationstartuporshutdown.
SayIamcreatingawebapplicationwhereIamusingHibernateasthepersistencemechanism,andIwanttoinitializeHibernateassoonastheapplicationstartsup,sothatbythetimemywebapplicationreceivesthefirstrequest,Hibernateisalreadyconfiguredandreadytouse.WealsowanttoclosedownHibernatewhentheapplicationisshuttingdown.WecanimplementthisrequirementwithaHibernatePlugInbyfollowingtwosimplesteps.
CreateaclassimplementingthePlugIninterface,likethis:
publicclassHibernatePlugInimplementsPlugIn{
privateStringconfigFile;
//Thismethodwillbecalledatapplicationshutdowntime
publicvoiddestroy(){
System.out.println("EnteringHibernatePlugIn.destroy()");
//Puthibernatecleanupcodehere
System.out.println("ExitingHibernatePlugIn.destroy()");
}
//Thismethodwillbecalledatapplicationstartuptime
publicvoidinit(ActionServletactionServlet,ModuleConfigconfig)
throwsServletException{
System.out.println("EnteringHibernatePlugIn.init()");
System.out.println("Valueofinitparameter"+
getConfigFile());
System.out.println("ExitingHibernatePlugIn.init()");
}
publicStringgetConfigFile(){
returnname;
}
publicvoidsetConfigFile(Stringstring){
configFile=string;
}
}
TheclassimplementingPlugIninterfacemustimplementtwomethods:init()anddestroy().init()iscalledwhentheapplicationstartsup,anddestroy()iscalledatshutdown.StrutsallowsyoutopassinitparameterstoyourPlugInclass.Forpassingparameters,youhavetocreateJavaBean-typesettermethodsinyourPlugInclassforeveryparameter.InourHibernatePlugInclass,IwantedtopassthenameoftheconfigFileinsteadofhard-codingitintheapplication.
InformStrutsaboutthenewPlugInbyaddingtheselinestostruts-config.xml:
<struts-config>
<!--MessageResources-->
<message-resourcesparameter=
"sample1.resources.ApplicationResources"/>
<plug-inclassName="com.sample.util.HibernatePlugIn">
<set-propertyproperty="configFile"
value="/hibernate.cfg.xml"/>
</plug-in>
</struts-config>
TheclassNameattributeisthefullyqualifiednameoftheclassimplementingthePlugIninterface.Adda<set-property>elementforeveryinitializationparameterwhichyouwanttopasstoyourPlugInclass.Inourexample,Iwantedtopassthenameoftheconfigfile,soIaddedthe<set-property>elementwiththevalueofconfigfilepath.
BoththeTilesandValidatorframeworksusePlugInsforinitializationbyreadingconfigurationfiles.TwomorethingswhichyoucandoinyourPlugInclassare:
Ifyourapplicationdependsonsomeconfigurationfiles,thenyoucanchecktheiravailabilityinthePlugInclassandthrowaServletExceptioniftheconfigurationfileisnotavailable.ThiswillresultinActionServletbecomingunavailable.
ThePlugIninterface'sinit()methodisyourlastchanceifyouwanttochangesomethinginModuleConfig,whichisacollectionofstaticconfigurationinformationthatdescribesaStruts-basedmodule.StrutswillfreezeModuleConfigonceallPlugInsareprocessed.
HowaRequestisProcessed
ActionServletistheonlyservletinStrutsframework,andisresponsibleforhandlingalloftherequests.Wheneveritreceivesarequest,itfirsttriestofindasub-applicationforthecurrentrequest.Onceasub-applicationisfound,itcreatesaRequestProcessorobjectforthatsub-applicationandcallsitsprocess()methodbypassingitHttpServletRequestandHttpServletResponseobjects.
TheRequestPcess()iswheremostoftherequestprocessingtakesplace.Theprocess()methodisimplementedusingtheTemplateMethoddesignpattern,inwhichthereisaseparatemethodforperformingeachstepofrequestprocessing,andallofthosemethodsarecalledinsequencefromtheprocess()method.Forexample,thereareseparatemethodsforfindingtheActionFormclassassociatedwiththecurrentrequest,andcheckingifthecurrentuserhasoneoftherequiredrolestoexecuteactionmapping.Thisgivesustremendousflexibility.TheRequestProcessorclassintheStrutsdistributionprovidesadefaultimplementationforeachoftherequest-processingsteps.Thatmeansyoucanoverrideonlythemethodsthatinterestyou,andusedefaultimplementationsforrestofthemethods.Forexample,bydefaultStrutscallsrequest.isUserInRole()tofindoutiftheuserhasoneoftherolesrequiredtoexecutethecurrentActionMapping,butifyouwanttoqueryadatabaseforthis,thenthenallyouhavetodoisoverridetheprocessRoles()methodandreturntrueorfalse,basedwhethertheuserhastherequiredroleornot.
Firstwewillseehowtheprocess()methodisimplementedbydefault,andthenIwillexplainwhateachmethodinthedefaultRequestProcessorclassdoes,sothatyoucandecidewhatpartsofrequestprocessingyouwanttochange.
publicvoidprocess(HttpServletRequestrequest,
HttpServletResponsere
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 高端車(chē)位代理銷(xiāo)售合作協(xié)議范本
- 汽修退出協(xié)議書(shū)范本
- 鋼結(jié)構(gòu)加工協(xié)議書(shū)范本
- 橋梁拆除重建與交通疏導(dǎo)合同
- 農(nóng)產(chǎn)品配送中心租賃與經(jīng)營(yíng)合同
- 特色餐廳廚師長(zhǎng)聘任合同及菜品創(chuàng)新與營(yíng)銷(xiāo)方案
- 城市核心區(qū)商鋪?zhàn)赓U合同模板
- 餐飲店租賃權(quán)及設(shè)備購(gòu)置合同范本
- 餐飲連鎖品牌餐廳租賃合同樣本及品牌宣傳協(xié)議
- 橋梁支座灌漿飽滿(mǎn)度技術(shù)專(zhuān)題
- 2025年貴州茅臺(tái)酒廠(chǎng)集團(tuán)招聘筆試參考題庫(kù)含答案解析
- 2024年財(cái)政部會(huì)計(jì)法律法規(guī)答題活動(dòng)題目及答案一
- 湖北省襄陽(yáng)市普通高中2022-2023學(xué)年數(shù)學(xué)高二下期末監(jiān)測(cè)試題含解析
- 如何答題?如何使用?請(qǐng)看這里
- GB/T 7984-2013普通用途織物芯輸送帶
- GB/T 16940-1997直線(xiàn)運(yùn)動(dòng)支承直線(xiàn)運(yùn)動(dòng)球軸承外形尺寸和公差
- 校級(jí)優(yōu)秀畢業(yè)論文評(píng)審表+畢業(yè)設(shè)計(jì)評(píng)審表
- 2022年德宏傣族景頗族自治州工會(huì)系統(tǒng)招聘考試題庫(kù)及答案解析
- 管道工程量計(jì)算規(guī)則
- 雪山上的達(dá)娃讀后感范文5篇
- (完整版)道路交通事故現(xiàn)場(chǎng)圖繪制課件
評(píng)論
0/150
提交評(píng)論