What is the difference between servlet config and servlet

Answers were Sorted based on User's Feedback

What is the difference between servlet config and servlet context...

Answer / mamta singh

Servlet config is a private area for every servlet.Any
variable stored there is accessible to only that servlet
while sevlet context is a shared area for every servlet in
an application.In an aaplication every servlet can access
the variable stored in servlet context.

Is This Answer Correct ?    203 Yes 20 No

What is the difference between servlet config and servlet context...

Answer / sulthansheriff

Servlet Context :
In servlet programming, the servlet context is the
environment where the servlet runs. The servlet container
creates a ServletContext object that you can use to access
information about the servlet's environment.

A servlet configuration object used by a servlet container
used to pass information to a servlet during initialization.

Is This Answer Correct ?    89 Yes 27 No

What is the difference between servlet config and servlet context...

Answer / amit singh(mca ,niet)

servlet config is a configuration object used by the
servlet container to pass information to a servlet to a
durimg intialization ,before calling the service method to
a request it calls the init(servlet config) to intialize
the servlet ,at this time it loads all the parameter the
servlet neede, if you need that some parameter only has
relation with the servlet not the whole webapplication you
should to go with servlerconfig ,we use it in
deploymentdescriptor,if you want those information those
you want to use for whole application in which many servlet
so use servletcontext
caution is that :-try to not use servlet context in web
application becaz they are not thread safe
and in deploy ment descritor you use like that:-
i think u got the right answer ,and best of luck
AMIT SINGH (MCA,NIET,greaternoida) and my email id
amitsing2008@gmail.com for those want more answer related
to java

Is This Answer Correct ?    57 Yes 8 No

What is the difference between servlet config and servlet context...

Answer / m.sridharreddy

Servlet context is a context for all servlets under the web
application.in the web application there is only one
context.and all the servlets communicate each other through
context and it uses context parameters
In the web application each servlet have one servlet config
object it uses init parameters.

Is This Answer Correct ?    41 Yes 12 No

What is the difference between servlet config and servlet context...

Answer / kalareddy

servlet context hold the info about application and servlet
config hold the servlet info.

Is This Answer Correct ?    38 Yes 11 No

What is the difference between servlet config and servlet context...

Answer / venkat

1)The "ServletConfig" , Config stands for configuration.it
is about deployment values you have configred for the
servlet.mostly those values which your servlet might want
to access that you dont want to hard-code,like may be a d/b
{one of the reasons you dont want to hard-code"you have to
recompile the entire servlet if you wish to change a single
It is Unique for each servlet(in a layman's language,one
can treat it as local variables to a particular method).
if you wish to change the values,you can do it by modifying
DeploymentDescriptor(in other words:web.xml)

2)ServletContext(they might have named it AppContext
instead of ServletContext):- you have only one
ServletContext for an entire application{NOTE:-.only if the
application is not distributed, in other scenario,you have
one for each JVM}
you can think it as a bulletin-board, where you can
put up messages (called attributes) that other parts of the
application can access.{in a layman's language one can
treat it as a static values}

you can use it to get server info, including the name and
version of the
Container, and the version of the API that’s supported.

Is This Answer Correct ?    16 Yes 5 No

What is the difference between servlet config and servlet context...

Answer / srikanth

ServletConfig :-

-> one per servlet or one per JSP

-> this object is usefull to pass additional information to
servlet and to gather information about servlet. so this
object is called right hand object of servlet or JSP

-> servlet container creates and distroyes this obj with
respact to our servlet obj creation and distraction.

-> Non java web resource programs of web applications
does't contain ServletConfig obj.

->ServletConfig obj means it is the ibj of class that
implements javax.servlet.ServletConfig interface. this
class name changes based on the web server or application
server we use.

->this obj is usefull to read intilization parameters of
servlet that are configared in the web.xml file.

ServletContext :-

-> one per web application.

->ServletContext obj and its data is visable and accessble
in the all the web resoure programs of web application. So
ServletContext obj is also called as global memory of the
web application.

->Servlet container creates this ServletContext obj during
the deployment of web application and distroys this obj
when web application is stoped or reloaded or undeployed.

->ServletContext obj is very usefull

a) to gather global inti parameters / context parameters
from web.xml file.

b) to know the details about underlaying server where
the web application is deployed.

c) to know the web resource programs of the web

->ServletContext obj means that is obj of a class which
inplements javax.servlet.ServletContext interface. this
implementation calss name will change base on the web
server or application server we are useing.

Is This Answer Correct ?    10 Yes 2 No

What is the difference between servlet config and servlet context...

Answer / khushbu ajmera

A: ServletContext: Defines a set of methods that a servlet
uses to communicate with its servlet container, for example,
to get the MIME type of a file, dispatch requests, or write
to a log file.The ServletContext object is contained within
the ServletConfig object, which the Web server provides the
servlet when the servlet is initialized

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.

Is This Answer Correct ?    13 Yes 7 No

What is the difference between servlet config and servlet context...

Answer / gaurav chauhan

You can take it like as every servlet has the same
ServletContext but every servlet has its own ServletConfig.

For Example: If you want the name of your company and email
address appear in all pages of your web applications then
you use ServletContext.

Is This Answer Correct ?    6 Yes 1 No

What is the difference between servlet config and servlet context...

Answer / ganesh

ServletContext object is used to give the
initparameter(Context) values to each servlet written in a
web appliction
but in servletConfig is used to give initparameter values to
only to specific servlet in which they are mentioned at the
time in web.xml file

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More Servlets Interview Questions

What are cookies and how will you use them?

3 Answers  

what is meant by servlet to servlet communication?

1 Answers   KPIT,

Directive Include and Action Include how both are working in JSP, what is the difference between both?In which suituation we have to choose these elements?

4 Answers   AZTEC,

when the jsp page is translated to servlet?

5 Answers   HCL,

we cant Override Jsp Service method?Why?

4 Answers   Infrasoft, Mind Tree,

How to handle the debug errors in servlets?

2 Answers  

How native code can be used in a servlet?

0 Answers   IBM, TCS,

How can you maintain servlet chaining?

1 Answers  

waht is the main diference b/w servelts and JSP ?

8 Answers   HCL, CAP,

how the jsp page can be regenerated?

2 Answers   HCL,

how can you give alias to servlets?

1 Answers  

Hi Friends, Suppose you have a web appliction which consists of 100 clients are connected with Connection pooling and they are associated with 100 connection objcet and connected with DB sever,Due some problem DB-Server suddenly crashed and server came to down state for a while after few minutes DB-server once again up,Now how will I manage my Pool Management with my 100 clients...can any one tell me??????????????????

3 Answers   ProgressSoft,