Advance-Java-Servlet-1
Advance-Java-Servlet-1
Servlet
Server
servlet container
Servdet1
Web Brov ser
responte Servlet2
DataBae
Servtet n
Def:Interface i InterFace
we alo san, serylet i
method wo
whia preient
olass lko implements servlet inder faceneed
te impleremontaioY to all Hose
method
Def 3 Program
Servlet isa pogmarm mlhich is goung to run
n rver meaning e
Servket progoram
orfac’ rlangey recbangle incle ’ ser input mve,
DATE
2)
1S
(17) 8 (1) 20
22 23
(25 26 21 (22
30 31 32
33 34 36
servlety
to decide mleh
particalar regueat
0e,, Servlek to call
means
or tge
'DATE
aandled
servlet contoiner, ServBet caotctner fll leive
request he requert mapped to wlich
servlet
Servlet Comtainer i take HTTP equait
to Cneate Tequest abiect
we dealingqwith Tava Applicalion
HTTP protcoso iE needto be
Canverted into Tava obiect, then hat Tava
obËect will be passed ta the ervlet.
servlet container willtake take aA HTTP
convert t into HTTe Servlet cquet
abieck
NOTeg Servet containr wil instantiate o cervlet
obieck hen gring to pass htte
HTdP Servlet Recruest oajet Sonto Serytet clase
rturn serelet will retunesponse
and it wil be in foxm af obiect
(HTTR Servlet nespmieobet
What 1S
Servlet 4 Generíe Sorvlet S
Seryle <i>
void destroy ()
Called b servlet container tondioate A
that
Serylet oeing ken out of service
DE
SrenericSerylet <c
'Generic Sorvlet' lass
Boterface
A
implernenting SerSorit
methods of Serylek tnterface will be
vlet
oheritod in enuieGerlek. a generic Seryle t
implemntatlon to those. netod is
provided excopt for' service metbod
service ( method
method Crenenic Servle clar
abstact
<i> |Servlet want to Creal
Vserulet.t.
<e<ab)Generic Serylet RcOmnendedto
inherit Generic Serutet
MyServlet clas and override
serivice C)method
Parameers nae
calli method
Hae
name
perameter
Return Sting i PLia
Shing lizalom the valeac
tontai ningUparameter
A tmes poLrameter
method
caataioarameder
publie. enumeation <Sring qetInitlarametrName)
namnes Can be retievd
Returns 8
Enumerationi t iotiodject contata
name servlel parameter
o public String qetServletName.()
Returns name serulet instanc.
6) public void log ( Sting
Wites the specified meltage to Serlet
Ale
PrintWnter :
co
class in Jaya ie. pat o
jnxa .io pevidt
pnckage metaods to write foamatked tes:
Methods far wikina datai
Print Writer provides a variety ofpint () e
printlnCO metboda for wmitin diEferent eindt
of including integer Floating
ata fleating paot
Dunabers characters Oand ating
E¡i print Cint ). paint (doale),d pxint (ting),ete
Read fom data GenericServlet (o-isp-form
The eq qetfarameken (Shing nome method i
oceyal volut para meker
fom the cients reg. in Contet of serylet
melho is benéiaid for extrocting
data Bubmitted toeugh HTML formy
Argumant i paratheter-nam
method takes parameer nam aJ
án
argumuntho's npnesmting
parametek alus
the hame
NOnt to ehica
The method retuns
Haat epreient sting
the vae ofspecified
pernmeter
retnfofr abent
absent paramter
DATE
paramter name
HTTP Servle & it'sme lhod :
Servlet
NorE
packo
HTTPSer&let-Ps abthact cass
though Hhere noabstat methocl în
Metholr oP HTIRSerylet
#doetc)
1hi methodi
called
uSedto
hen
handle
elient
httpget
sendi a
Cquest using HTT
Crek methd Ty pically getR
fox aperatiag thhtdo
neiReguest
not uave Side efects Suoh
information Sisplagian resore
retieving
Tn get eueat alta appended
qupryparameters
DATE
Query parameter
îo contezt ol servlet vefos
ralor
to e paro meters that incude in th
URL of HTTP Tequest
These Pammeters are addad to tho end
4he VRL aftera questin aack and
questionpaack
Separaled
CPuery arameters mmoay ed to
Send data from he cient sehver
DATE
ormat parameters
Query parameters sppended i URL afler
qeatic makk ( 4 mullile patameters are
separeed by (&)ampersanod
t Webservlet
This standad annokaicn in J2EE for
Serylets.
declaring is a partafo then Jayax. Servle annotaion'
paclkage
Step S E Detoyy
Destoy the ervlet
web contaier wiU invoke :y)metho
cloy
loefore
wi lbe unload' ng
destroyecd.
Sérvtek clas Vservlet
operation w'l
serylet' Ufecycle aappen any mce
need
launchiag
to
web-applicatico
Specific page t o be open ot
moditication
in "web. xml
<welcoone-ile-list> taa
tag will aelp to set which
needs to opened vohen a n applicatHon
launched,
In the weleone - file-ist Can contigure
multiple bueleone Ciles
<web-oapp
<welcome -file -Lists
<welcoe-Gle A. btmd <welcone- ile>
<welcomie- file B. htm <wel come-kile
<welcone- file) Cihtml <welone-Pile>
</welcomae- ile-list>
Klweb-app e have multiple elCoYme Cile îo
welconue File isttwi wosk f-lse
adder, TÆ page A,B.andC not auailable
hen wu Hhow Error 404 page not found
all Specify welcoefile lisk
defautt indexjsp
when 0 POge wiu open
an
web-appicaEon launched
abgolute path, elabive path
OScape seguonce characher DATE
clag? oading proces 3
-
>Advantages i
Usingload'-m-startup
Serule
can be beneficia) Aor
Lhat
need to perforsm initializoton
task setup es0wrces when applicatic
starts.
Use-Case
Tnflfallios databo connections. Establishin
Conmunea with lexterna resoroes
DATE
configurakim solting
<lald-on- startup
We- Ca ses
utilizing
used
Tn gummary, oad-m-stact aponderol to
Condral he 0nitialzaton ensureg -a Sere
in a eb-application. TTE wree hat
serylets are loaded and intialized wben
the applicalion ctarts AL hem to
pertorm ke sks setup tagke belon
andleng dlient eguott. Loadl-on -starho
Hhena pariculac
Secvlet wi be loaded l initialized onu
hen egLnted.
valee
sCenarios Hhat mitht hoppen2
0 Serrlet comtaàner expects poiti ve integer
waleees
value
<load-on- startup> tay
in <load-onsBartup> TE negaive
prerided it miglat be ignone
treabed as ernor énterpeted
unexpected bethari our' not
standardizei Cacoe Servlet -containers and
conlainers
different
walies ALfferealiy migut handle negaie
zero innalie :
vaue pot valid value in
<load- on. stactuptaqit expecked pasitie
inteqerssEtb alue is provdod it might be
ianeoned. treated as
Bhaviaur
an erro 0
intepetdgl
differen serylet
eantainer
Ratt Dispatcher
Request Dispatcher
The Requast Dispatcher
Servlet prorides way Tnterface%
to
Tequest
indade
from fosward the
rvlet to other seryetvle
the Content
resources ( servlet, JSP, HTML)in another
LE is
mainls wed fe Ahe respane
duringrequast procesiog. erver-side forwar
the basically helps
where to where
Servlet to othor Servtet
Servlet to
to other TSP/ HTML
OR
tram JSP to JSP
OR
rom e SetoSerylet
)uolic
Dpualic void forward (Serylet Request neguat,
ServletRerpmse respens)
For a Request Dispatcher cbtained vic getRegkBapa
snet Request Dispatcher (O, the Serdet Reguett abíeck
VbasPts path elements and para metert
adiusted to math the path of target resurtc
Cor ward shauld be called before the respaas
has been Committed to cient
Forwards request from sevlet to gnother
(selet, ISP Pile, or HTML Gle) on thR Server. resoure
DATE
Porameters
request ;
ServletRequest obËect that nepeseuts the requ
helient makeg oe serrlet
Tesponse
ServletRespnJe
respomse he
obieck
gervlet
that
etun
TRpresents
to cienk.
the
Servlek Exception
TOException
TlegalstateExaption
)public void incede CSerelet Requeit requsk, Seletfupn
mesponse )
Incudes the Content oea nesouce(serulet,1Se, HTM
Hhe response.
» formarding
entiret
Foyardis achieved csing
method of OrequestDispafdher
forwarde)