Professional Documents
Culture Documents
%!
Q:Explain ServletContext.
A:ServletContext interface is a window for a servlet to view it's environment. A servlet can
use this interface to get information such as initialization parameters for the web
applicationor servlet container's version. Every web application has one and only one
ServletContext and is accessible to all active resource of that application.
%!
ServletConfig: The object created after a servlet is instantiated and its default
constructor is read. It is created to pass initialization information to the servlet.
Note: Most Servlets, however, extend one o] the stcndcrd mplementctons o] thct
nter]cce, ncmelyjavax.servlet.GenericServlet and javax.servlet.http.HttpServlet.
17.How do I support both CET and PDST from the same ServIet!
%he easy way Is, just support !S%, then have your doCet method call your do!ost method:
21.What are the dIfferences between the ServIetConfIg Interface and the ServIetContext Interface!
ServIetConfIg ServIetContext
%he ServletConfIg Interface Is Implemented by the
servlet contaIner In order to pass confIguratIon
InformatIon to a servlet. %he server passes an object
that Implements the ServletConfIg Interface to the
servlet's InIt() method.
A ServletContext defInes a set of methods that a servlet
uses to communIcate wIth Its servlet contaIner.
%here Is one ServletConfIg parameter per servlet.
%here Is one ServletContext for the entIre webapp and
all the servlets In a webapp share It.
%he paramvalue paIrs for ServletConfIg object are
specIfIed In the InItparam wIthIn the servlet tags
In the web.xml fIle
%he paramvalue paIrs for ServletContext object are
specIfIed In the contextparam tags In the web.xml
fIle.
0IsAdvantages
O Every UF on a page whIch needs the sessIon InformatIon must be rewrItten each tIme a page Is
served. Not only Is thIs expensIve computatIonally, but It can greatly Increase communIcatIon
overhead.
O UF rewrItIng lImIts the clIent's InteractIon wIth the server to H%%! CE%s, whIch can result In
awkward restrIctIons on the page.
O UF rewrItIng does not work well wIth JS! technology.
O f a clIent workstatIon crashes, all of the UFs (and therefore all of the data for that sessIon)
are lost.
40.A cIIent sends requests to two dIfferent web components. oth of the components access the
sessIon. WIII they end up usIng the same sessIon object or dIfferent sessIon !
Creates only one sessIon I.e., they end up wIth usIng same sessIon .
SessIons Is specIfIc to the clIent but not the web components. And there Is a mappIng between
clIent and a sessIon.