Advance Java Servlet 2
Advance Java Servlet 2
SendkediectC:
The Send Redirect (3 method in Servtet R
ese to reolirect a clientls request to
another esouce, eher witi Same
web-aPplication external weh-applicaton
Cexternal url 2 TLismehaod i part f HTTP
Servlet Response Interface (HTTP Servlet Response <O)
>Redirecting to another esoure
The
mdiect
SendRedirect c) method
nesponse to
sends
sends a tempor
thelient
the clients browser to make instructnq
nenm requert
to the specified url
SendRedinect (" uurl !)nterna ttnk ke
eip. agmenk gateuca
uRLs
The URL can be relatine to curre nt serrle
URLs
absoleutewRL
RLîncluding externad
perates
Entfrely Server.side Ini<fates
client-sde
request from
Software Server i
A coftnware applicatfon a progranm Hhat ru
aomputer and provides specific services to aliet.
Ea web-serrer sofware ke (Apache on
database senver sofhatare (pastqregq ysql)
Yurther ne can have multiple definitions of Server
as services, web server, applicakim server, server farm
datacentre
Multiplk webapplittons an he stored on the serve
oil be an Rdenifter(us
tOn erey application there will
Any sppYicatin acCessed by intenet s called a
w~b- applícations.
Whenever dient is request, it contains
URL tmethod
ethod typesending and data.
Ih req obieck,
get/post method bye, URL, and data can be queny Paramkrs
Response contains *s tatus code,tcontent type,*contt.
Content -type i TE is HTTP beader that îndicotes
bupe of dota contained in body of HTTP respmse.
speces 4he media hype of content heing
sent.
>status cade : Astatus eode is three oigit numeric
code retumed by Server to indicate out com!
of clients nequest maale throughwebbow ser
megest side URL 1
para meters
requst
*URL App URLS
method App"3
Data TApp2
respomse
Client network ntermet
Server
4 Statue Code
content type
contenb
-)1XX Informational):
These status code indicotes Hoat he
halreceived the clien! requast and igerver
e
Continuçng toprocess it and wil! provide
Cinal re spomse later.
2XX (Suce ss fel ) i
Theie tatl code indicateg thatclientk
equest suCceRrfutly received yndertood
and accepted
tedet 4Xx (ciient Erros) :
These stotus code indicates that client seente
to aave made an
issios ke requeit with malfunctBon or
unanthotjzed CccesS.
3XX (RedinerHonl):
These statue cade ndicatee that turther
actínisequied ta to complete the requegt
SXX (Server Error
These ctatsCode indé cates thot servet ha
Lencountered an erro while fulftling the reae
It's not cients foult and serve isisUresponsbe
Tesolving Hhe ss ue
Servlet 1 Servlet 2
Serylet 3
D8Canti
SeryletContext
web-apptcatior
In web-app Servlet lemtext i an object
e) what kind of Object P
Serrlet Conke xt kind of obËeck.
#What is Serylet Context object ? who is respcnsible "
Tt is an object in web-app and web- ton tainer wil
Cne ate ServletContlext object. Asaproggomnar, no nedl taomy
Ho to Store alue in SerletCntext
whenerer were otoing songething in ServtetConkexk
DbËect, wehe going to ore îtit in keyyale pair
These key- vale pair wU be stored în wwehxm
'DATE
<context -param>
<param-name> key <param-name>
<param-vaue value slparem -value
<lcontent - param>
We can have multiple <Contet patam>
When does ServletContext obieck is qing to be ceat
we
dapla web-opplicationit is cedb
Annotaion
DATE
Senvlet Config
Servlet A.
Servlet Conial
Serrlet B
Servletonis
Serslekc O
Servetonfia
web-app it One fox Serslet
a
object
Servlet ConfigÞ obierk of Serylet A a not visible to
Serslet Configandbieck
Servlet C
ServlekB
Serslet Config obiect of Serlet R not
Sessim
Step I Creationi
A sessicrn neate he Ainst time when
usen -accessee the webite
tep Session
Session
Timeout ?
Lhave timeout ! wer s ina ctive for
Speified duration
Juration the session expires,
Task &
there in 'DATE
Houw many
mamt
Sessiom.
g
Tava
ree
Servlet . tracking
lessioo Tracking
There are multie way by lich we
track Seseion, an
2) URL Rewibing
Sessionid e appended to URL
gerver Rt treated as
hence Server member who the cient i
in the next request. Tais is Lstate lesr bokeyio
Soagain client necds to itroduce to serve
erery requsst to Kerver.
To avoid this we ne adko take helo of sesto
by which state ful behaviaur can be achieved.
(S&rrer will ecognize client hcough mutife
egests)
4What are Coogkie
Cooakie are Smal piece of data stoed on
user's cients device web-bro3seL
Purpore o coockies 9
D>seselon Management
Coonkies hetp iinn f o r k e r sensing, They
stoe Sessio
stay lu4ged in as allowing
theywebsit
nacigat though
users to
A Cookie in Java o
Tavax. Serylet.bttp. Cooekie.
olo3t is preJent
Initkally Caokie
Cookie
is Created in
Serstored
ver hyom -
Server, the hat wil be
sponse and sent to the client.
he
client will take
The hose Cookies ond
store it inbrowser.
When client makes another reguest, client
uillsend
iqutst along
Lnq with.
with cookie,
NOTE & Tn cOOkie we shore daba in kayyvalut.gi
We n CTeate Cookie object with help of
Comstaucton, in Caokie class wehavé to
Comstactcons
) Cookie ) f