Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
35 views
41 pages
Unit 3
Full stack web development notes
Uploaded by
ajaypanyala29
AI-enhanced title
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
Download
Save
Save unit 3 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
35 views
41 pages
Unit 3
Full stack web development notes
Uploaded by
ajaypanyala29
AI-enhanced title
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
Carousel Previous
Carousel Next
Download
Save
Save unit 3 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save unit 3 For Later
You are on page 1
/ 41
Search
Fullscreen
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 CamScannerCommen 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 CamScannerSteps 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 CamScanner3) 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 CamScanner5) 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 CamScannerclass ‘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 CamScannerVoid 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 CamScannerThe 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 CamScannerEncedit 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 CamScanner1G 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 CamScannertold 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 8> < Seleck name = "Colon" slae o>
Red < option >
é
dbr> Cinpuk type = Sabri valute =" Suber” > < [fonmn> <] bodys
= “Qa1een" > Gareen
= “Bice” > Blue
% The sounce code for Colon get Sowle: java is shown in the following Usting, The doget o> method Is cMertidden to procs any dP get requests drat ane sent to dhic seowlek» TE cues dhe gekPasramekenl) method of; Ake Seale Req wee fy obtain this selection that war made by the user A mesporue is chen Jormutoted - Scanned with CamScannerImpoott joule to. a import joviaxs seawlel x5 impont java: seule. HHP. 5 public clans ColomgelSewlel extents dtlpSewlet public wold dociet (MUpSerulet Requtert request, AL PSewleReporre response ) Ahaows, Serulet Exception, Toexception Sbring color = arecqyuert- et farameke(" colon”); | riesponse - sek Content Type C" tert / Kimi “De. | Point Written pus = mespomre - get Waker (ey peo painthin ("e@> The selected colon is: "); pro priinttin (colon); po close 7; 4 Compile The seaulee and perform “these steps be kek this example : |i Skank Terneat , if HE le not already sunning }2- Display the \leb page mM a baowsen. la. selec a colon | |4. Suber the Wleb page | ¥ After completing these Steps, dhe browses) leoill display the response that is clynamicatls qenornked by the Seulee » One athe poink : Panarmekens fom an HTP GET mrequucsk anc inclucled arn park of the ORL hat is cenk to rhe Wleb Senuen Assume hat -the wsen selects he ied option and submit the [pam The ORL Seat prem the batounsen | fo -the servers hUP : I (ccathos Bo80 / era ples [cerulet / ColorGebSenlerd Scanned with CamScannerColon = Red. The chanactens to che might of +the Vuestion maik are known ar the ane shiv landing ATTP POST Reqyuesks - ‘d a % Alene ae eaill develop a serulet tha& handles an HTTP POST rmeqyucse- The Serulek is Inuoked when a form on a Web page is submilledl. The example contains two files. A web rage is defined in ColomPost him and a serial te define is shown in othe follovsing Usting . TE is identical to ColomGek-him except that the methed parameter fom the foam bag explicatly | specifies ~thak the Post _methed should be used and the action panameten fom he form tog Specifies iffenentt sewle Zbody > | eeeere | Cfosimn naee ="Foami’ method = * post” action = “hip : /| localhost :to8e /e xamples / sewlel ( ColorPork Serutet "> 2B> Colon:< 18> “chon” sige = "> “Ped” > Red< loption > © Geom"? Carcan< lopk o> Cseleck name =
Blue
< [select > gbar
einpak bape = Submit value " Submit’ > < Koon > < [body> <[himl > Scanned with CamScanner(The sSounce cade p> shown $ @) ColomPost Servlet «java is WW Ahe [allowing Usting - The doPost C) method is OlOImidden 4o PROCerr ary HTTP POST. request te Obkain the selection thak war made by Whe wren A siepome is then foomulated . Impont yastarios x» ‘tenpomt jowax - sowlee x import ‘yauax- senile + hitp 5 Public class Color fost Senutet extends UlkpSewlet g Public wold ofost (HtipSenilek Regu —arequeit MitpsenileLResporse rteaponse’) Ahriows Senet Exaption, Tobragion | Shing color = nearer: ack fanameben(" color") presponse » sek ContentType Ch kerk | Kent" 5 Princ Wik: pus = esponre sg ccWriiten td; Pe painnC’
The setected color iss"), Po. prinkln Ceolon) pus: close ©) 5 {3 Compile the Seswlek and Perform the same steps % deswibed In the previows section to test ib Scanned with CamScannerNote: Reorarnekers fea an HTP POST request ane nok \ncluded as pont of the ORL ~fhat is sent the web sever: En his example, dhe okt Sent form the boowser to the sewer is + to hitp : // locathost : s080 /examples/ sewlet / Color Get Sewlek The panameker names and Valuer are sent 1 the body of “the 4ITTP reqyuest Scanned with CamScannerOo Using Cookies Now, lets develop a sexulet that illudrates hou to use Cookies. The sewlet ts invoked ashen a form on a Web pege is submitted: The example Contains Ahree files as auremaniged hene : File Desaription AddCookie htm Allows a user bo spedty value fea the Cookie named My Cookie * AddCookieSewlet java Porocesses the Submission oh Adeicookie hem #* GekCookiesSenulek + java ‘Displays cookie wellirer, * The HTML source cade fon AddCookie- htm is shown in Ahe following, listing * This page Contains a text fila in which a value can” be entered Toe is alto « submit bublon on the page. when this fubkon is preased, he value in the text field is sent -to AddCookie Sewle ula an -HTIP Post request - Zhe?
gcenken> Cfoam name ="Foum\” methed =" post” action = “hllp:// local host :8080 /examples / senulet / Add CookieSenulet "| 2B> Enten the value ie MyCookie : <(B>
respovne - sekContentType C* kext [hkml") ; Pontlsiker Pur= srespone - gee Waiter; 3 po: printha Cea MyCookie ha» bem set -to") Scanned with CamScannerper prrinkkn (Cdako) ; ® Pus: close); = The sowce cede fpr Geb CookiesSewulet .jevd is shown ‘in the — followi Listing. TL woke, Ahe et Cookies) method +o mead Cookies ‘that ate included in the ant Get dreayuest The Names and Valuer of these Cookies ane then eositten bo Ane HTTP aesponre Observe that the getNamed) and getValue C) methods are called to obtain his inpparation import — Jastato-%; Import jauar: seule, Import Javan: servlet http. %; Public dass GekCookiesSewlee extends Hitp Serle . public uoid doget (HlepSewlet Request mreayucl] HupSewleeRespome mespore ) Aracws SewvlebExcaption, To exception MW Get cookies from header of HTTP request Cookiel] cookies= request: gekCookiex 3; WU Visplay these Cookies aresponse - sek ContentType CU’ kext] hem"); Prinkinriter puss response qetwaiterdd; | poo: printta (<8 >"); ! Fon Cink \20;1< cookies length pier) : Sting name = cookies (\]-getNorre() 5 Sting Volue = Cookies Ci get Valued; Pwo pasinkto C name = "+Namer” value Value) Scanned with CamScannerpus close C5 3 Compile the seuilek ond Peifoon hese steps: Fe Stas Tomeats ify IE ts nok abteadyy stunning. a Display AddCackie hen in a beocosen- 3. Enter the value ‘ton My Cookie 4 Submit the web Paqe: Alen completing dhese steps gow will obsewe. | thak o fedioack Mmesaage is dlisplaged by she | browser. Nexd, request the following ORL via the bamwsen | hike: /locatthost ! Beto/ examples /senulek / Get CookieSowlel Dobsewe that the name and value of the cookie ane cisployed in the brewster. x In this example, an expimation date is nok explicitly assigned to the cookie via the sekMay Age O method ob Cookie. Therefore , she cookie expines when he You Can experiment: by waxing sekMaxfige Od and Obsenve that he cootie is then Saved to the browser sesmion ends disk on dhe client machine Scanned with CamScanneron ‘Tracking HTTP ts a Skakeless prrctocal. Each sequest is independent of the previous one. Hlouseven, in some applications, ik is Necesrary to save Stake information so thek infoameakion can be collecked fiom seomral interactions bebween a. browser and a Seaver. Sestions provide such a mechanism ~ A session can be oteaked ula the Ate Session) method of HEpselet Request « fn HkpSession object ts sekumned. This object can Store o sek of Bindings that ovrcciate nannes celth objects: The sek Athsinbute >, geeftbiibuke 0, GtbAbsiibukeNames? > and memoeAtoibuke ) methods of Nip Session manage these Bindings « TE 1S imporkant to rote thak session stake is Shared among att sthe seawleks hat ane asicciaked wth a pecttiaatan clienk *~ The {pllowi sewlee illusbiakes how lo we session skate ~The gresesion> metkod gets Ahe Gemenk session. A new session is Created if one loes not alneady exist. The gebAltoi babel) method is called -to obbain dhe cbyeck tha is bound le dhe name “date”. That objec is a Dake ctjeck thak encapsulnter the cate and Kime ashen “his page eas Lusk accessed. A Dake objeck encapsulating the omen dake and inne is then Creaked. Te set Atsiibaked method e Cathed cto bind dhe name “date” he this chjeck - Scanned with CamScannerimpomk java io. x; impomt jowa util 5 irnport Jewar- seule x5 Vrnpoat Javiax: senile hile 5 Publ class Dake Sele extends LUpSewlee t public void doget (HikpSewlet Req west srequest | UpSewlel Response mresponse) Ahorows SerlekException, TOEXception UM Gee the -lepSession object HUpSession as= req west: gt Session (tue), MW Gee waiter arespomse - Sek Conkeak Type C’ eext P html”) ; Prin Wlriikesr pus = mresponre- getulaiiten (9; Por paint ("
"); MU vispley cake / bine of lank accent Dake dake = (Date)hs gtk Aibibute Cdete'} , ik (dake |= nett) pes paint C* Last access:*+date +° fbx>) 3 1 Display cwerent date / time date =new Dake Cd; hs. get Alsibuke Ci dake", dake); pusrpaiadls (" Curent date : "4 dake ); | 1 Scanned with CamScannerWhen you fiat mreayeeat this seavlel , the 5) browser dlieplyys one Cine esith dhe cusiment dake and ‘time infomation On solsenteemt Anvocations, two lines cate aisplaged “The fuk bine hows the date and time eshen dhe Sewiet was lak accessed. The second line shovss dhe cauoent date and -lime Scanned with CamScanner| % Dibreduction te TOBE 2 | > Tn leday's Scenario, Many enterprise level applicalons heed to Mirae With databases a stewny wwloranton. | 5 For Tis purpose, We wed om APT Complication prigyam ming Tulerface) ie ODBe L open Dalabate Connedivill ). 3 The ODBC APT was The datsbate APL te conned- and enews query With We dalabate + Buk, opBe API “Wes opee inc language Che plakie dependent dvver Which 1¢ halle and unsecurad)+ > Trak ic Why jove hat defined Irak utes Ippe dvivers called its oun APL. pee (teva Database connodivilf ) + gor -tten fm Java language). he Ipec drivers ava MOVE compatible Ut ote communi Caton cone om doves th Jove. Apalne 4 exewle query tat fe connak With te pride dalab > apec ib a jeva APT to Ie dalabote. Ipwe APL dakabose + > Apee Supports aud eaty fo ule: uses dbo a idle. level ob pata biltly and Ipse | is Siemple | > In IRE APL, & pragvamme | ts peutic dolla bate + ie needs a Spetite driver | te connect i RDBMS Diver | estore sane einaiepapal | ovale oracle. ydbe - diver « Ovocke Driver | oo | MySQL com. mysql sjdbe «Diver SyBose com» Sybase. jbbe . SybDrivey Gar Sewvet | com- micvo soft.yd be + Sql Server ont. com: ibmedba» jdbe+ nel Der Davey «Litt db Some popular Driver te Scanned with CamScanner* apee Archi! The main-findion oth The apge is to provide a glsvdayd abshaction for “ave applications te communi cadiom niTh database + St ova Applicaton | pee | APT - | — | Driver [paver wage | \ a ‘ sce es] | —_> vs vole ee , | me 29:- the Ise Avchledioe ns Shon wo Here, The Jove application iat wont to Communicalé With a dalabote hat to be progvammad using Jpre APL: The ‘Tore Davey ib sraguaved to process tra SOL “veguesle and generele the neesulls. ; he TDRE dyivey hat fe be ply: om im tanl- vole 19 conbiiclina. Te Diver” Mavagey uses ete tively connet™ speufee databases “5 Type Davey is a Soflware comporouk- Hhok enables java appicaton te vbyauk with he dalabote - Some Spoke te DBC dvvers Ye With Scanned with CamScanneri Theve ave 4 Types of ape dvivers, tose ave, > Type -! Diver ( JoRe- oppe badge vor) | ly type - 2 Driver (partial spac driver) java diver for middleware) mm dive database conan) \ > Type ~ 3 Driver Cpuve | > Wpe- 4 Driver (pave java dvvey wi % Type-l Diver (aDBe - OpBe iradge d-dver) diver ack as & oridge belween THEE | mechanisms Such as Opec: | | and other dolabase connedivily Te Ippe-opge badge driver uses obec aw Tes {pa =i yey te conned dge dvivey comverti JDBC fo tke dolabate + re IDBc- ODBC by methed calls whe opge method calls « seve Applicaton jf apee Apr dt DBC Davey Managet apac- pec bridge avev OPBe Diver vendor pelabete Libary | Be Bridge paver £ig: OPBe- opi Scanned with CamScannerAdvantages : x Easy fe use- & Com be eatily Conned@d to any dalabate - Disadvanliget + X per-famance dagvoded becaute layge number ob trans ~lakions (ie appe calls fe opee calls). client ¥% The opge dvvey veods te be insalled on the Machina. * Type-2 Diver Cpovtial IoRC dvivey) :- ies s the clienk - Side Liby called as Nokive- APL dwver. ints Maltve. callt so tt is The Wpe-2 dvivey use tie database So Ths chiver 1s alto converti Spac wmelhod colle This driver is ek whatten endively i Java, A me database Apt. Te called as partiol TOBE dvver~ Teve Application apee apt TRE Diver Monaget pg Nakive APL dvivey Scanned with CamScanner| Aavowlagers x pecfdmance upgaded Ian apge- ape bei lea, yer, x guifatle to use With Seyvey - side aapplicoinn s « Digadvawlag: 04% x this Native chivey me x The Vendor client Library neods to be the cost af the OP on defeat plobformt middlawore ) t= i X “ype-2 Dave Cpave geva vive Jor imnplamenled in Jove, | client Modine mocking, ods to inslatled on tar each indlalled on cliewt Aicakon uy the apaication X Tk Wey incyeate Weeds te van tre type-3 davey & comple tely ec dey jcabton The type 3 duver uses middle wore Capplical a "a aly inks tee ver divedly O° inde called as Nekwork protocel | hence if is o pure Java 9D! server) | trek converts TDBC calls ~speurhe delsbote profecel ° ik dvver- Java Appbcadon dpBe APT [ Spee Paver Managey Nawork profocel Drjvev Middlentave. Vendor . yb Scanned with CamScanner| Advonlages ¢ | | vw no clenk cide Ubyary is ~eguivad on clienk Sida. | and auls downloadable - x pave Java dvvers | Disadvaubigers a Nebwork Supgork 1s Yegul is costly compavad to cthey dvivers« \ X “Type -Y Davey Cpave_ ove chiver, with deyoet_dalabase. Connedlag)- ddver, Which converti! databose profecel | vad on cliewk Machine. K This dvivey The type -4 dvver is a pave Jove Th vendor Speke pre calls divedly inte thin dvver- m as that why if ib Kou dave Application | Ipec ArT TpBe Diver fae Tun Diver — Dolabate Server . Fig Tin Dvivev- pdvoulaiges : ud ants daouloadable. x Ths divey 1s quer Java dvvey oa x Beller performance thaw all other drivers ne No Sollisave ts vepuved ab cliewk sida ov pisadvawlages : x Drives depends on tla Dalabate - ger Ver Side « Scanned with CamScannerye Dolabase pregrarming using apBe t- Apee Apr, ave used by a Java opplicabion fe communt cable wlite a delabate- Ga other words, tle use gree connedivity code tn Save application te communicate with a dolabase + There are 5 sleps te conned omy Sova application With Ti database im Java Using JDBC. They ove ot fellas + Sept t Regisley tke driver closs step 2: Creating connection Step 2: creating slatéemet | step 4: Execubing sar Slalemonk: | step 5.1 closing connedin. | Tre dviver class Wl | | x sep 1 :- CRegisler Ie doiver class) | ith diver Moi Sa this slap, ple vagisr th dviver val by using orNowne ¢3 mefhiod of class class Syloxt clacs -forname C paver clatt Name) wjdbe -dvivey- oracke Diver’) Exarnple: Clases eforName Covodle x stop 2 :- (cvealing commaton) Tn ‘this step, ble con Create o comneto | sever by using getConnacton C) method de DaverManaget © 9 aye shovg pod) | | wy with dalabate | tase. | “syns gelComnedtion (sting uel, Example + | Connection con = DrverMamager get Connection C * jdbc soractet thin t @localhost +152 1:xe", | ces tai: | > Sep Bi- Covsalivg statement) inal the, o After the connedin made, Kla need fo craale obyedt te ened the sar slatewaull. 1 Scanned with CamScanner 9The CyaataStatemauk ©) wetiod of Connection iulayface is used te cane slakmenk. this slalement object is sponsible fo enews sat sblements with The dolla bate + Ayrton: x: Cyaale Statement O | anit alament shat = con. Slatemeul O; x slap tu: Cexeubing sat Slalement) Alter the slalament object crated, it caw be usted | te enctuke the Sar statement by using execute Updo OO | ereeakeguary() method of clatewent interlace + The enceteQuevy method i oaly uted te encute | | Setect slatemewlt - | all The events Jpdala 0 miethed is used encuule sot ctalémouly excapt Serer Slalemente. Syrlx: enecale Query Cshivg qe) eneuste Update Cshing gusvy) Bamlet using nemo Query Shing que =“ Select * fever emp" s Resatheek ve = cla. ements Query (query) | [using enersle Update 0 dt inks emp Valuer(sou,'Macle,>9) J Shing quey 2" inde chk. emetuké Update (Query ); (slip St Celosing the _connedtion ) | aller enetuding oll Hie SOL clatemenli and obtaing Te the fe\Sion. vosutlt, yte need ts clate tie connedion ond ydleote close) wathed ec Connedion interface ce used te | Syrdoxer- close C0 con. closec) | Scanned with CamScanner The close the Connedin\* Example :- Ceonnectivily With oracle. database) or connecting java application WHTH The ovocle dalabate, | pe need 16 Know dellowing ivefermakon 13 perform dalabote comnedivily with ovacte+ Gn This example ble ove using ovecle 107 te elalobate, bo We nosd to Knew -fdllawing iv-forwodion duvey class by ovecte dallabate is * pyaclevjdbe «chivar. OrededraveY dev Te oracle 104 dolabase cor tee ovcle dalbedt x Davey class! The * Comnedtion URL? The connertion URL | is *ydbe toraele-t thin {@localhost: 1621 !xe" + | Where gabe Whe APT, ovocle is the dalabase, thin is the d¥vey, lecathost & fhe Serveyname. on Which ovocle is -Yunning , 152t is | te pork number omd KE Ys the ovale Sewice Name « ¥ Usemamet “The defautl patiword is given by the user ab te time ck imstalling tke ovode dalabate + x password t >To Comned Java application woith Ih evade chile is ~eguivad to be loaded. = Treva are two ways te load the ofelbely fellas avy one dy ture nyt 1. pasle The oydbely- jor jor File, We need Bile in “Jove. [are] Gblet” fldew 2+ Seb clascpath piestly, Search The ajdbety-joy ble When go “java,/fre| ub] ext” Adday ond paste the tov fle heve- for) Sak class path 5 To sak classpath, gots ewvironas Tier on waw [Gb» Sn Vovable meme vTAle classpath and Voveble value paste the path ts ajdbery -jav by appending pidbeluser ses as © ca\ovadlexe Lape ovacle\prduct \ 102 -0\ server Ab \ojdbetyiavs es", Scanned with CamScanner aah Vowable then usevnome fer Mu ovacle dolabase is “slew | \5 | | dokabase oydbetrser| & Excomple i Lelle first Crsalé Fin ovate database» a table cmd inserts tuo of wiave records name Varchar2 luo) , id Number (12), seu> create fable emplid num pioneer at sal> inser ils emp veluet (S01, Madhu’, 20); gars insert tate emp Valet (Sor, ‘Havi', 32) cat> insert into emp vebses ( Sod, "colt! 33; press)! conned? Jove egplication Mith Ovecle dafabats for Selecting |e | ov oakiving data caladkafe vjove | import ovassgl %? iagore jove.-DAL.%: | class Seleupate € be slalte void main (Sting ovgst2) t | Wy Cn slept load Te diver class \ Class fornlame Cavacte sit be dive. Qvacle Diver") ; Wop 21 cvaole tke commedion objed Conneckivn con “ydbc :ovncdle + wer managey get Connection ( Smt @locathote1S21 xe", “oyslew"," advuia'S + ‘step 3: cxeate The stalomenk objed Slalemenk slat = cone Cvante Statemenk (9s W Slep 42 eneude guery Retulkce yy = stat enetale Query (“Select * dom emp") 5 uskile Crs. mexbO) . ‘ato. euks printhe (rs. gelTuk at Te yeagetstingoo+ a 5+ get hing@2)) 5 3 tistep S: close Te tonnedon objede con. closets 5 | otek CEneaphon €) J Systm smab-piatl Le} i Scanned with CamScanneroutput: Die Jovac selecbdalas Jove pia jeva Seled-pata Sor Madhu x Sox Hawi $03 sob 33 sms? conned Jove applicakin with oracle database efor twlevtiy | data. ieqpork geva-Sal 3 import java SRLS class TnsertDala public Sfadie void main Ching avgst3) { hy chiver. gvackevvet ngs Class fortgne. C "oyacle «jdbc: Igonnedkion CU jdbe + ovacle + (hi Connedon con = Drivermanogy qe! t@ locabhost : 121 2x2", Sgyslemn™, Nadkwita!) 5 Statemant slab = con: creat Staldwerk 1; ghat. eneualeUpdele Cin ser = emp velues (504, ' Gavesh’, 283)! Syslewn- out pinkle (* Susevlad «+ con, closeors 3 caléh CEncagtion ©) t ; system out panty C2; 4 i outpuk: Di\> javac Talertdata «save Di\> java Stet dala. Ansevted +++ Scanned with CamScanner% program: java application ulith oracle databate tor update cela.| Updelecials | vapor Java Sql ee; Import Jova-VHL closs Updatedata t public static void main ( Sting avg st3) { bey { class forniame C"ovacle wdbe- diver. oracle Diver J; Comedtion con = Diver Mamages - gpd adbesomle trims @ localhost: isa zxe.", “system”, “odrain") 5 Statement stust = Con- Cvaate Slatement (5 Sit. enevate Update ("update emp sek age 38 Where Syston cook printla C updabid + - ="); con: close 1; id= $03"); coleh CEnoptin ©) it et System: cubs pyinth (" Enteption +205 eo Dt/> jovac Updalednla .yove. p:}> javo Updaledalr Updolad vo + + % DraverMovaget _Closs | class 3- The DaverManager class au at an Werface bekooon wlev and drivers. Ok Kaas Hack de the dvvers thak ave auabiable ond haudles establishing a cownedtion beboaon a dalabate ond the appr) ealé davev. Scanned with CamScanner
You might also like
Unit 5 - Servlet & JSP
PDF
No ratings yet
Unit 5 - Servlet & JSP
187 pages
Java Servlet
PDF
No ratings yet
Java Servlet
71 pages
Module 4 Bis402
PDF
No ratings yet
Module 4 Bis402
69 pages
WT Unit3
PDF
No ratings yet
WT Unit3
77 pages
Unit 3
PDF
No ratings yet
Unit 3
43 pages
Servlet Architecture and Life-Cycle
PDF
No ratings yet
Servlet Architecture and Life-Cycle
15 pages
Serv Lets
PDF
No ratings yet
Serv Lets
85 pages
Java Web UNIT 2 Servlets
PDF
No ratings yet
Java Web UNIT 2 Servlets
24 pages
WT Unit-4
PDF
No ratings yet
WT Unit-4
58 pages
Servlets - Servlet Overview and Architecture (Unit 5)
PDF
No ratings yet
Servlets - Servlet Overview and Architecture (Unit 5)
89 pages
Unit 3 Servlet
PDF
No ratings yet
Unit 3 Servlet
122 pages
Unit IV - Servlet
PDF
No ratings yet
Unit IV - Servlet
47 pages
UNIT 5-Server Side Processing
PDF
No ratings yet
UNIT 5-Server Side Processing
27 pages
JSPServlet
PDF
No ratings yet
JSPServlet
86 pages
Module 4 Servlets
PDF
No ratings yet
Module 4 Servlets
109 pages
Serv Let
PDF
No ratings yet
Serv Let
107 pages
Advance Java Servlet 1
PDF
No ratings yet
Advance Java Servlet 1
25 pages
Servelets Notes
PDF
No ratings yet
Servelets Notes
6 pages
Unit I
PDF
No ratings yet
Unit I
38 pages
Unit 1
PDF
No ratings yet
Unit 1
37 pages
WT Unit 3
PDF
No ratings yet
WT Unit 3
41 pages
Java Servlets Notes
PDF
No ratings yet
Java Servlets Notes
50 pages
Serv Lets
PDF
No ratings yet
Serv Lets
17 pages
Servlet
PDF
No ratings yet
Servlet
16 pages
Servlet Interview Ques
PDF
No ratings yet
Servlet Interview Ques
20 pages
Servlet Introduction
PDF
No ratings yet
Servlet Introduction
9 pages
Servlet
PDF
No ratings yet
Servlet
24 pages
What Is A Servlet
PDF
No ratings yet
What Is A Servlet
12 pages
Servlet
PDF
No ratings yet
Servlet
25 pages
W-T Unit - 3
PDF
No ratings yet
W-T Unit - 3
28 pages
Servlet
PDF
No ratings yet
Servlet
49 pages
Unit 2
PDF
No ratings yet
Unit 2
56 pages
Unit 1.1
PDF
No ratings yet
Unit 1.1
22 pages
Java New Servlets
PDF
No ratings yet
Java New Servlets
109 pages
Server-Side Programming: Java Servlets
PDF
No ratings yet
Server-Side Programming: Java Servlets
116 pages
Presentation of Servlet
PDF
No ratings yet
Presentation of Servlet
37 pages
WTUNIT-III Material PDF
PDF
No ratings yet
WTUNIT-III Material PDF
22 pages
Servlet Assignment
PDF
No ratings yet
Servlet Assignment
7 pages
Dashrath Nandan JAVA (Unit3) Notes
PDF
No ratings yet
Dashrath Nandan JAVA (Unit3) Notes
20 pages
Java 6 - Servlets
PDF
No ratings yet
Java 6 - Servlets
22 pages
Servlets Notes
PDF
100% (8)
Servlets Notes
18 pages
Unit IV Servlet
PDF
No ratings yet
Unit IV Servlet
13 pages
Introduction To Servlets
PDF
No ratings yet
Introduction To Servlets
11 pages
JAVA Notes
PDF
No ratings yet
JAVA Notes
42 pages
Adv Java Complete Notes For End Sem Exam Preparation
PDF
No ratings yet
Adv Java Complete Notes For End Sem Exam Preparation
30 pages
Chapter 6 Servlet
PDF
No ratings yet
Chapter 6 Servlet
39 pages
Unit III Servlets
PDF
No ratings yet
Unit III Servlets
18 pages
Module 1 Advanced Java Servlets
PDF
No ratings yet
Module 1 Advanced Java Servlets
15 pages
GR22 FSWD Lab
PDF
No ratings yet
GR22 FSWD Lab
3 pages
Servlet
PDF
No ratings yet
Servlet
3 pages
5-8 Lect Servlet1
PDF
No ratings yet
5-8 Lect Servlet1
89 pages
Unit - 4 Java
PDF
No ratings yet
Unit - 4 Java
13 pages
72 Servlet
PDF
No ratings yet
72 Servlet
72 pages
Chapter 3
PDF
No ratings yet
Chapter 3
48 pages
Introduction To Servlets
PDF
No ratings yet
Introduction To Servlets
38 pages
The Servlet Life Cycle
PDF
No ratings yet
The Servlet Life Cycle
24 pages
Introduction To Java Servlets: Vijayan Sugumaran School of Business Administration Oakland University
PDF
No ratings yet
Introduction To Java Servlets: Vijayan Sugumaran School of Business Administration Oakland University
38 pages
Introduction To Servlets
PDF
No ratings yet
Introduction To Servlets
93 pages
Servlets Training Session, CGI, Hyderabad Date: 14 MAR 2011 - 15 MAR 2011
PDF
No ratings yet
Servlets Training Session, CGI, Hyderabad Date: 14 MAR 2011 - 15 MAR 2011
33 pages
Serv Let
PDF
No ratings yet
Serv Let
5 pages
What Is A Servlet?: Javax - Servlet Javax - Servlet.http
PDF
No ratings yet
What Is A Servlet?: Javax - Servlet Javax - Servlet.http
4 pages