Servdets
Gele
’Servlet i6 a technologa which is uSed to e t acept
ch Teucst and to qonerate weh Taspense.
Wcb Agplicoien :
’The appicaticn which i5 pxesent inside a distant Systesm
and which Can be gcess oVe the intenet using stndad
web bxouSOdS
tNote Each and eseoy xob babed applicatien Series Seme
data ot tho intosmaten en the web ox întennet
web ResouNCe >
Nob 0souTCe is ag dato o iDtox aien presont sn
the web Ctnteanet).
1) taic web Resoltoce ’
’ the dota or intuxmahisn psesont sde as u0eb sesouTce
doosnt change with. Seme cendihien s is_ called as stacic
wob mesouYCe.
R Dynanic wcb ResouTce;
’ TTf the data oos the intosahisn) praeht as a wcb
esouTCe changes based en Seme csndiiens is caled
dyramie web OSOUD Ce.
Note i) stoic ucb gesouTce can be devcoeed ing HTML
HTN
Dynamic web TesouTces Can be dovebped aing HTML+JS.
ii) Since, fs is executed in he client side system.
it is not SecuNe fpy
lo oVenCome
(gsp).
fox
this
Senstive. data Lintomahen.
pxoblem we Can
Can deuelep dynamic
USng semvlots et Jaua sonvon phgas
V) Ihe dynamic cb g050ux ce uohich has been doyeloped
chiat side
USing hML and IS will be oxeuted at cliont
but the dynamic web QsouYCe which has been
deucloped wing sevles technalogs nll be executed
at server and lside
14 H 3
Client -sexvOX Anchitecuse;>
All the uoob paqe applicahen tollou diond- server ardtectwe.
web equest
chent web Tespense Sexvers
* Note:> NJth tiox axchitectue ct web based apelicathens.
In the abave diagram hore is cnly ene
graent at senver end. so it is calbd a or
architecuNe.
InIh n tieY archihecuze we àll haven
Systen prent at the senney end.
To order too send a ueb geu to pasticulay Semver ,
wo haye to locate that Semven tinst and then
We Can locate the wcb TesoiCe pseset insdothe
Sexvery.
To locate oXoT idevtiy the web sesousce on the uwdb ue
hawe tomake use d
(Unifoym eLouYCO LoCatur)
URL sands foy Unstoim ResTce Locatos' ohich is wedl
to locate he serVer n the web.
URI Stands tor ' Unifom Resautte Idorbifies' uhich is uaed
to idenaty the web g050uTCe praL ent inside a seVeX.
URL omat i
DYotaco: | host-Dame : poot-namben pah to-esouCe RquoMystina
Nore:Apache lom cati ’(wob soxver)
’ In ordoy to 5ervet o 7e80 en the web we haue
to make uso ot web Servers..
|Ne dze qoing to make seSe ot Apache Tomcat.
Senlots Hiexaschy :
Sexvlats wll act as ApT'5 betwecn cient -side applicatien
and senvert-side applicahen.
lo Cxeate Sesvlets we can Use the bolow mentiened
Servlat hienachy
Senvlot (Toterta ce)
Gtenyic Sert vlet CAbshrac class)
HTTP Servlet (porthially Abstac cas)
Steps to Create a Dynamic udeb poject i’
Step-1 pxess chlt N, To CHeateaa new dunamicweb. project.
Ster-2 - seaxch tor dunamic wob projec and select Dynamic
Wob projec and click &n nox
Step-3’ In the next window provide pxoject name and check there
is a apache tomcat semvon auailable astatqet Tuime
and hen cick sn next
step-lia Th he next indou, uithaut making any changes
dick en next
step-5: Tick the checkbox as MGienenate [Link] deployment
doscnpter. and then lick Gn finish.
Stucuye af Dunamic Wpb Pooiect
Sevlets
>Deplayment Dacaiphaa Sersaltr
JAX-WS web sorvices
7Java Resoursces
Srclmain liava
VLibrabies
build
SyC
-main
-java
webapp
- META-INF
- WEB-TINF - b
web. xml.
Diteient uwaus to creahing Senuleb in Tan; ’
Senlets axe special chsses in jaua
) By Tmplemonhing Serlet Irntertae
2) By extending" Genenc servlet abstact dass
3) By estending HItp servlet pantiolly abshact clas
The ditesen ce betwoen Generic Servlets and HTtP servlets ’
Gteneric Sexulats HTrp enJlets
QGereric serVles Can i) HTTp Sesvlets Can accept
accept anuy type of enly HTTi suasts
Ex HTTR, H¾TPS, SMTP |) Thats why HTIP sex ulets are
FTP etc prdtocol depcndent.
WTha's uhy qenenc sen vlats
Ge potocdlindegonderd
@Wcbservlet Annotaten ’
This annotatien is used to auto cotiguxe serlet inside
web. Xml which arepts ene
Gne shing pe atsibute rd paten.
*Note;-’Widely ubed Servlets ate HTTP Servlets.
(Secause of pxatocol deeendany af HTTP)
’RequEst disutcher is anintesface plesent insideax.5ervgbt.
RequestDispatcher
This ioterface Used to dispatch in osder to dispatch sane
Tequest to Seme cthene web Teuest within the applicatien.
include(o method :> (pres ent înside egest seruleb)
This metod is used to include the despense o web
60SouSce trem ohich we a8e dispatching the regust alsng
wsth s0spense o wob sesoYCe to beohich we
dispatching he web egGt
*Fotuard 0) method i (present inside seCst Sexulet)
fus waYd (74, esp) is used to exclude the xespense
of a web seq est fstm whch we ane dispatching the
Tequest and just respsnse tf a wcb gessce t which
disgathing the equest is încluded.
Send Recisect() mothod i (prserd inside zespanse serlet)
This method is used to edis ect a Teuest to
3rd ApL'S.
Difosence bewech fouwavd () and sendRediect ) i
Send Request )
i) foruwdO is used to i} SendRecivect () is Wsed
dispaBch the Sanme nequest to qonexate aa no) Tequest
to Seme atber wob tors thixd pasty APIS.
Tesousce wtun the
aplicatien
D) forword) is psesert i) sendRediect () is psesert
inside HrTpServletReguest insde HTTP ServletRespense
intenface. Sioterface
*Sarvlet Lifecycle i>
*Sevlet containex ox wob cstainex
’ Senlet containe is comgonent of web Sexvex which
manages Serdlet Gtecycle
staqcs în
Diferent sages Senulet iteayde ;->
4)Loodipg of servlet
Tnstantiabsn
3)Tntializatien
4)Sewice
5) Deshuchien
&) Tnstatiatien ( Serlet containex wil CYeate an obect tors
Teuested Gemvlet
3) Inialzaben:5ervlet containex oill invoke init) method
of a reuasted sonvlet to initialize equiTed Properhies
ot a seqIested Servlet
4)GoTVico ):’ At this stage senvlet Containex will invoke
Sesvice () method of a soquested sexulet which defines
the behauiour ot a senvlet
5) Destuchen of servlet :> At. this stage the senlet l qot.
destoy by the servlet container t úhich it invokes.,
destoyc) method of a s0guested senet.
Nate: In the erdie litecycde of a Servlet intialixatien and
dasu chien will take place snly Gnce but Sevice mehed
LUSIl be invoked 'n ot times.
(whene, n ’ no. ot Keauest )
’Whonelen a web 7e4u0st is mapped o a Senulet.
Geryldt Catainex will Creae Sevlet Request and
SeruletRespanse objects.
* Javo SeNes Paqes (JSp) *
TSP stands to Java senvex Page
Jsp's similas to HTML document but they ill be executed
Seves- side system
If the to CUS is MOTe sn9n applcahen logie then senylet's
Ye ecommendedf the torus js moxe en data presertahon
then Tsp's eCommended
XNotei TsP techncloqs is implemented based sn Senvl et
tochnakgy
Diferent stages in Top ifeccei
1)TSp o Sevlet Fans lahen by Tsp tanslatos :>
Mith the help ot tsp tanslatr we convont sp to
ECLIT1)
sevlet.
2) Loading ot semvlet’loading process
8} Tnstahahen ’ ebfect uoill be Created tor Serylet
4) Tnitializatien ’jspInit )
5) Service C) ’-isp Service ()
6) Deshuchien. ’ jspDestroy ()
JSP Togs’
1) Decavaive Tag’ <%<
’his tog is used to decaxe java \aiablesoT methods.
This tog is Used to deine jaua logic inside JsP
3) Expxossien Tag:’ <%= %>
This tag is used to pint Nmables.
4)Diseadive Tag:’ <@
This tag is used to Jmpoxt exteADa esourCes in Jsp
Spring homewogk
Sping tameuonk i
Spib bameuwenk is a Jigbtuweght jaa fame ueTk
which is used to daelcp web based entenpnse jaua
appicabiens.
Spin faneueak will bciease the efficiencyd
development of lueb based jauaapplicatiets.
Since, itt povides inbuilt featuyes. So that progammex
need not umn
sem tho soateh
about dodlkging jaua agplicatin
Ih Jaua applicaien a proqxamex has to deal with
multple objects and then dependencies, ohich hase-o be
Danaqe by the proqsanex tslt. but if we make
USe spnng Ssameik he pxoqsammex neod not womy
about maraging the chjects in the aplicatien.
Th Sprng based aplicatisns chËeds are ctomed
’In
a 'Beans which ofl be Manace by the cempénentt
Called as Gppng CHrtaine
Spáng Centainer : ’
Spnng Containex is a Component of sping Samework
uhich manages the litecycle ot a bean în the applicatisn..
Beankocoxy:’ (supemtst intertuce for bean)
T is a spring container which managas bean lieycle.
ie)Cxeaten ot a bean
i) inihalizahion of a bean
usecase or a bean
iv) Destuchien of a bean
Hiexos chy of Spring Containexs
Beanfacty (r)
Aplicatisncortext ()
ConfouableApplicatisn Context (I)
’saing fameuosk Supposts apact oriented proqarming
iLe. the ane bg applicahen can be divided into Small
Small apphcatien Caled as 'aupoc'
Modules in Sping Fxameoctk ;
4) Spoing Core
a) Spring mvc
3) Spninq Boct
4) Sping CoNe >
Sprin Core deals uith the Core teatuYes of spnng
framowonk.
Spring hamework provides teatuves ike Toc &DI
8)Spang Mvci
MvC:’
Spnng mycC Can be bed to delelop Monolthic applicohisn.
Sever-Side ’ web sexVi Ce
client-5de
Pyesentatiern Buisness Database
Layer Logic Layer Layer
Prentend Backend Databae
monolithúc agplcafien
3) Spnng Root i-’
sping Boot can be Used to develop serer Sice
abplicaiens called au eh Seruice
1.4) Toc’ (Inversion ot Comrol)
’Toc shnds tos Tnvesien of (onmol.
’The Conrtsol of managing the beans. (objects)_ in he
applicotien ha beengven g CThverted) to spring
famowonsk. ton the proqrammer i.e. the proqrammr 1s is
olenger Tespensible to manaqe beans in the applicatien
’This process is caled as 'TnverTnvensien of Control'
1.2)
DI:’ (Dependency Tnjechien).
DT stards tr 'Dependen y Tnjedien'
Ttis the process f provid1ng öbjects in the applicaien
henouen nd wheseuox Te4uused. which uol be dene.
by sping Centainer
To Acheive Ioc, we haue to centiquse the Applicaien.
We can Cantiquse the applictien in Rwaysi
1) XmL Based Contiguatien
a) Annotaien Based contiqunatien.
Step-1Select the project falce and press cal+N ta (reate
a ne) SouxCe folder with the name Sxclmain Config.
Ghep-2y-clect the CTeated sonte Solder and press cal +N.
To reate an xm 5ile tors configunahien.
step-3-Deine the bans to be managedl by Sping Containex
MsingKbean~.tag
SCope ot beans in Spring Bsed Applicaien:>
4Singleten:>
’Ih Spsing Based aphcaien all the beans will haue
sngloten a a defaut scope Lohege all the define
beans will be Created and itialized as ston as
aplicahien Context is caeaked.
II the Scope of the bean is singleten than only ene
bean is Cieated and the Same bean will be given
by the appli caien context whenover equested.
2) Protutype:’
’
If the scope of the bean is pxootype then bean
boill not be roated alang wih he cTeahien ofot applcatien
Context. 2
’The bean wll be Creatoc and inialzed wheneuen
requested.
Fox each now Tequest, a new bean uill be Creat
Basic Annotations ot Spring ramewosk
1)@component >This anngtahien is used to mak a cass
as Component class for uhich spring containen
manages the beans.
2) @ Bean : ’This is Q method louo aongtatien USed with
the factrsy methods. AASping Containex invokes
afactony mehad dofine inside antiqusahen class
wbonoven Tequise d
3)@Scop0:’ This annotaien is sed to detine the scope
of the bean. Csingletn ox pratotype)
4)@Vaue;’It is aa propers lovol annotahien used to
boan prcgoties.
intiaze bean
5 @Autonedi’I is aa plopexty lewel
leud annatahisn which is
LAed tooinjet chiece as aa dopendany
6)@Compencntscan :’ This annotanien is used en top of the
Contiquxahien chss in ordox to detine he
basd package in which we want spaing
sping
ontaingn to seqrch tor the compon ents.
7@pimasy:’ It is 4 class lovel annatoien chich is used
to preter a bean of pvticulay cass for DI
Luhencuerswe havemulfiple uadisying beans
fox the same deçendeny
&@Qualihed:’ TH is a property leuol ahnatchen whch
is Used to prefon Bhe degercency ameng
muläple qualiting beans
* Note' IH We axe making use of ghe of the qualitying beans
S a dependency forx enfire applicahen Contex then
make we of pimaay annotchien.
I the depanden y does not enain constat in the
applicahen ortox t then we can make use of agualihex
annotheh