0% found this document useful (0 votes)
35 views41 pages

Unit 3

Full stack web development notes

Uploaded by

ajaypanyala29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
35 views41 pages

Unit 3

Full stack web development notes

Uploaded by

ajaypanyala29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 41
Scanned with CamScanner | o | Senulet technology is used f create web application (mesides ak sewer side and generates | dynamic web page ). | | * Servlet technology is robust and scalable because of java /anguoge + Befone servlet, 42 ( Cornrnon Gateway Dnterface ’) seripting | Language was popular as a serwer-sice | pox pramming law e- But there ane many disadvantages for his Cechnologe * Tene are many inkexpaces and classes in he seowlet APT such as Sewlet, GeneriieSerulet , AitpSerulee, SerwlekReqyucrt, SewleRespome etc | Whak is o Sewlek 9 | Sewlee Is described in mony ways depending | On the conkext- * Sowlet is a technology te, used fe ceoke web applicalion x Sewlet is an APL thak paevides many tinker forces and classes inchuding clocuments x Sewlee is an inkexpace that must be implemented for venting any sewlet * Sowlee is a class that evtend the capabili- ties of the sewers and seeponel “the incom meqyuerk ‘LE con stespond fa any types of reeqyuent Scanned with CamScanner Commen Gatewey Taterfoce (cqz): cq technology enobles the web sewer te call an external propiam and pass 4ITP dieqreste infoamotion to the external program fo process the steqyest- For each rd, VE skamty a nes process Disadvantages of CGI yo There ane many problems in cat technology : D Th number of clients increases, it tnkes mone time fen sending mresponse 2) Fox each request , ik stants a proce, and web sewer is limited te stant processes D TE user platform dependent language - eg C,Ctt, pot Advantage of Sewlet : “Mene arte many advantages of sewlet over CGI. Te web containen creates dthoreads fpa handing the mubliple requests be the sewlee Fineads hove a bot of benefils over the processes Sach as the shane a Common memar! onea, Gat weight cask by communnicobion aa “hal Atineads “ane lous “the base benefit off Senulek ane at follows + a) Betten porpoamance : because ik wreates a thread for each mequert nok paocesa- Scanned with CamScanner ») Feoitability : S beenuere iE gives jaura languoge ta 2) Robust + Sewleks are Managed by JVM So we don't need to cory about memory leat , jooboge collection ete: : 4 a) Secure + because ik ares java larguoge Like - Cycle of a Servlet : ‘Three methods ane central to the bfe cycle of @ Senvlet +» Mese ane inik(), service) and | desboye> They are innplemented by oy sonulet | and ane invoked at specific birnes by Ke cenver | Lek us cConsiden a typical user scenotio to understand ashen these methods axe called. ~~ Fistsk, assume that a user enter a Unifon Resounce Lecatoh (uRL) te a Web brouter. The bnowsen then generates an HTTP meqarest for dhis URL. This request Is then Sent to -the appropriate Sewer x Second, this AITTP reqneest ts received by dhe web Sewer Te sewer maps rthis request J a panlicutaar sowlee The Sele is clynamier hy netrieved and loaded inly the address space of ihe sewer % — Thind , the seven ‘wwokes the Init rnethed of “Ihe Semlet + “This method is invoked only tohen cine Servlet Vs foul Loaeted into memory, Jat ts posside to pam iniiatigation poormmetens fo the seek so men configuae itself Scanned with CamScanner %* Fowrlh , the server invokes the service ¢) method of the Sewlee: This methed Is called to porocess the HTTP request You will see that it is passible fp7 she senvlee bo read data thal has been poroviided ‘in the AITTP sequresk Tk moe alse pormutiake an ITP response p21 the chem #* The Sestwlet stemains in the Sewers laddoven’ space and ‘s available te process any ether AMITP requests received fiom clients. TRe Seowicet) methed 1S called fpr cach ANP requrcd % Finally, the sewer may cletide to unload the sesiter ior YG memory +The abgesithies by echich AWS clekernivation Is mode one specific ke each Sewer The sewer calls the desnoyes methed fo aelingyuish mesowoicer AUK as ble handles hak ose allecated fpr the sewlek, Cinpwatante dake may be saved to 0 peuistane atone. The memory allocated for ‘the sowlel and NL objects can then be grabege collected Scanned with CamScanner Steps b crake Servlet Progam : i) create a dinectory shructwie D create a senvlet 3} compile the servlet ) create a cleploymn ent. descriptor 5) stork the semen and deploy dhe pardject 2 Access the sewlek D create a dinectomy shuckwte « CER - INE HTML | classes (folder? css | _eseb- vent (file) [— lib ( fotderd |— java coudere of Sewilet D) gente 2 sewlet: serulet can be created in 3 diferent ways A) By Implementing Senet wncerface » By inhesiting the Genoiic Serle chars ¢ by ‘whesiting Ane Attp Seorulet: class. Scanned with CamScanner 3) Compile the sowlet = | Berle can be compiled by using Jon files | Jor des are sequined to be leaded. Servlet - opi jor v SE can set dhe elarrpath or ik can be copied veal into Ahe Seowen. | 4) create deployment deroiiptor : Depleynent desciipton ie an vmL fle «sith Rame web-amh + Faem dhis amt file web container ges pthe “intpamation about the sewlee te be “tok « web.amh filename 4 /Sewleb names SSewvlek ~ Chass > Aaunome < /sewlek — casas < [servlet > < sowlek — mapping > ésewlek-Rame> filename < (seowlet —narnes Cupik - patkenn > steplia < (url-pattern s < feerulek mapping > web -opp> Scanned with CamScanner 5) stant dhe sewlek and deploy Ae Tree ane te cone te Aeploy the a) hod Aeployrnente B) Sob cleplayenente ® soft, cleploymente: Copy the demo folder into seaver morally An Wedocs Cie, server) Copy & Paste the complete elder of dhe project - Tn appache web-apps is the server C21) xampp [omcak | web —apps * Copy corepleke folder b) Soft deployenent: | Foo sobt cleployment frase Greate a wan fle by compnessing al files (i-€., Zipping ) a oan pile is gina % % 7 * A cor fle is Cteaked asitih Jon commands localhost "2080 / manage [htral. D: [>Vemo/ Jan cvf demo war} 8) Recess the serwlek: hilp: IH locathost /Pemo — if filename ig nck specified then ie ioreckly access index html. ‘Scanned with CamScanner * A ‘The Sewlet API : Two packages contain the clesser and inkethace cthak ane Rrequined fo build Sehuleks + They ante a) Jovan seule B) Jawan -serulet- hip a) Jawan + Sele package : Tnkerbace_ i ___ Deswiiption - Seorwlet, Declares lifecycle methods for a seaulet Servlet Conhig Allows servlets to get iditintigation pastamebers Seaule&Conkext | Enables servlets to lag even and access information about their envinonment SeuletRequest | Used to oead data from client: seq west Sewlet Response | Used to urmike data to a client reaponse , Single'TioreadMoael Trdicakes that the sewlee is Ahteod Safe Scanned with CamScanner class ‘Deseiplion Generic Serurlet: Seowelet Lnpert Sbrearn Serurlet Oak put Sbream Seruleb & xcepron | Unavailable Exception Samphernents Ane Seale and Sewlet Cenig tnkerfaces Perouldes an input shea fp>, reading sequel fron a cheat provider an output clea {um fenitivg mesponten too cle indicates @ senulek enor occuned Indicakes a sewlee 1s anavail-| able. (TL declares the init | Ae Gte cyte of om |The Servlet Interface Lat ceawlets musk “implement -the Seowlet Anterjace methods dhak ane cotled by dhe sewer duaring by seule ane shown iW lable below ©), Sewiced) and destroy seule. The mekteds defined Method “Desoription Nord deste “f° » Seoutlek Co bg gee SeowekConbigt ) ing, grtsowletinpo hak cenkains any initialisation called when the sewle& is unloaded - mekuins a SeawlekCenhig objec ponamekers mrekienns shiing deswibleg the senulet 1 Scanned with CamScanner Void init Sewulek Cen se)} called echen he sewlet is | thnowes Seulek Exception | iiialiged: Tniliatigation forametens fom the seule can be cbkained fom se. fly Unauailalble Exception should be ttotwen fy a sewle cannot be ‘inikicliged Noid sevice (Some Request | catlecl to prccess a rework meq, SeauleeReaponre ae )| Prem & clienk The req ucst Irom Ahe dient can be meod fron meq The rieapome to ‘TDoEKception Lhe chent can be conitlen to ner fin exception is generaked Wa Semule on TO problem eau Aporowos SesulekException, The SerwleteConhiq Inkerbace * ‘The Seautel Config Inkenhace Implemented by dhe seaver Tk atlows the Sewile te obtain Cont cotation daka uchen ik is loaded. The methods declared by “his inkeahace ane summarized here Method Description Seaulek Contest stebwoins he context fer shis qekseuleCentert (> [seule - Sing genie Barometer mela the valite of initiatigatie (Sbing param) [parameter samed Panam Enumeration _ [archon an enumontion of all gekTritfasamttentiamest initiatigation peramecer names Sbiveg gurSowlettame Cy] rekurns dhe nome othe ‘witeking sewvlel Scanned with CamScanner The SowletContext Toterbace The Seuilek Context ‘wkeifece is ‘implemented by Whe Sewer TE enables the seowleks +o obtain ‘nfpamakion abouk the Enuiswramenk . Several oh ib methods ane summesiged in table belo - | Method Description Object get Atatibute stekuant The vate off the Cstaring attr’) [sewer abboibute named atta Sbing gctMime Type aera the MIME ype of (sbivng fle) fle: sein qek Real Poth dtekians the meat path that Cornresponds to Ake Wartusl on ky (Sting vpath) path epath String geeSewerTnfpt) [returns iwiprmation about the sewer Acid leg CString s) wootikes s to dhe senlek ts oid log C-string Ss, lomike $ and the slack trace Tircwabte ¢) [ben te the Sette: leg lucid Setf\ttoit bute gets the oblsibuke speafied’ (sting alin, Objett val} by atin tothe value passed in val h SowletReq wes Inkenhace The SewlekReq west ‘nkeijace As “implemented by he sewn. TE enables a sowlel qo obtain ‘igyermaken about the diene nequak: Seweral a TK methods ane summeniged iy) able belous Scanned with CamScanner Encedit Sbi ebChanacker 4 a O int getdontent Leaginc ? Shing get ContentType) Seowlet Input Stream qteieret Sbeamt Aintows TOException Ski ek Pescamekort (bing prame) Enumeration get Parameter Nlarnes oO Csbring name) | [Sbig gettrctocsko Method Description Object getitint bute |Aekwins the value of the CStoing alts) |atrituke named off d Sting CI grtforometorllaluey aebwns an a rebwins the character enrocing of the req treat aekuoins the size of the request: Hie value -1 is aekemed tf te sige is unavalable. Aekwins the bype of the neque LA mult value in nedwined if he tyre camol be dekewnined nekusins “the Sowlel Tepul-Sream Hhak can be used to aead bineu) data peor le vequast - An Alegat state Ereiplion is Arevouan iy qekReadenc) har already bean ‘invoked. pr this, seqpuak nebuons the vole of dhe Poocamebert named prame nekwins an enumeration of tha parameter names for Hhis meqyreot Conkaining Valuer assotiaked aath -lhe poorarneken specified by name, rrekwms a desription of The protocol. Scanned with CamScanner | BuffredReader jrcboiw a baftened xeader thal ek Readent ) jan be sed to mead bert freea Abe nee An TlgplstaleCraphion is Hooeen if gektnpukSbreamc 5 han already bein invoked for | cthewows TOExce ¢tion Vins, reat [Sbing getRemoteAdane | metus the stiie | of dhe client sPaddoiew aivalent! [Sting Ae Rematettet 9) mekawiea the sting tayutvalent oh the Client host nore Shing qckScherne C D Jarekuois the Gianemiscian sthemng, | the URL ured fray the neque! | |Sbiveg QekSewertame cd rdw the narre oh othe Sewer “Ine gttSewerfont ) retrows dhe pork nunloer. Te Sewlck Response Lntedace The SewlekResporre inketface is implemented by dhe Sener. Te enables a senulet to foamulake a mesponse fp a atient: Seteral of ib methods are Summesiiged ‘in fable below Method. Desoiiption Sbi atekuans the chosracken encoding! gttchanackerEneodivgt fpr the mtespomse. Sew Oukg ut Strearn arekiowr a SowleeOukputShream qetoutpuestcauncey fat tan be wed to write birend Aynows LOEXcephen Koka to the response. An tI StoteException is Haoun if qeeweiterl) hos already ben loweked foo Ais meq | Scanned with CamScanner 1G Prink Writer geknikent)) rebum = Painewaiter that 2 con be cwed to wwriike character daka 4o “he mesporee . fin Hiss! | SkokeException is thon fy getoutpatstream) has abrendly bean intoted for TNs aeyual mows To Exception Veid set Contentlenath | sets the content length for the Cink ie nespore to sige: ucid sek ContentType sets the conkenk ‘ype (pr the C sbieg type ) response clo type ‘The Single ThreadModet Interface This Inkesyarce is cred do indicate that only a Single -Horead will execute the senwiccc) meted of O Sewtee aka green slime. Te defines no combanty and declares no methods. Tf a seiwlet ienplenend, cihis Inkerbae » dhe server has feo options. Final, ik can creske somenol instances of the Seowlek - when a lien rtequeat aontiver, TE is sent to an available Waskante of the sewle- Second, 1k can syneloworige access te the sowle- The Genenicervlek Clas ‘The GeneriicSerwlet: class provides teplernentations jof the basic Lite Cycle methods fora senulet ancl ie kypicably Subclassed by sewlet developer - GenenicSewlee tenplemnenb, the Sewlek and | SowleeConkig ‘nkelaes. Bn addition, a neni hs jappend a Shing to the sewer log file is available The sigqnakwtes off Ais method ane shown here: Scanned with CamScanner told log € Sting s) wid log (string <, Throwable < ) tere, § ts dhe Sbing te be appended to the log, and © is an exception dhak ecavted: Mthe. SewrleEAnpuk Sbrearn Class (the. Souleb dapat Socom Se “the Serwlet Input Sbrearn class extends ‘Input Stream, ak is ‘venplernented by seaue and paovides an inpu& sbyeam dhak a sete developer can use to ntead the data from the client reqyneat
Colon < Seleck name = "Colon" slae o>

You might also like