What is the difference between servlet config and servlet
context.




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.

ServletConfig:
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:-
<web-app>
<context-param>
<param-name>............<param-name>
<param-value>..........<param-value>
</contextparam>
<servlet>
<servlet-name>.............</servlet-name>
<servlet-class>..........</servlet-class>
<init-param>
<param-value>..........</parm-value>
<param-value>........</param-value>
</init-param>
</servle..
</web-ap...
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
name.
{one of the reasons you dont want to hard-code"you have to
recompile the entire servlet if you wish to change a single
value},
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
program.

-> 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
application

->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

Servlet Chaining? How do you do the Filtering in Servlets?

6 Answers   HCL,


Hi friends, am newbie to servlet. My interviewer asked why used servlet in your application. i used servlet for controller logic and business logic . is it correct ?

5 Answers   TCS,


what is the advantage of using Servlets over CGI programming?

4 Answers  


1.HttpSession 2.Hidden fields 3.URL Rewriting these primitive type of Session maintainance. What is the other type of process that could help to maintain the Session? pls Explain the process if u know?

5 Answers   OnMobile,


What is the difference between ExecuteUpdate and ExecuteQuery?

4 Answers  






How we can check in particular page the session will be alive or not

4 Answers   Symbiosis, L&T,


What is use of parseQueryString?

1 Answers  


What is done after deploying a war file and before client gives a request

2 Answers   Bosch,


What is servlet context ?

4 Answers  


Can we use javascript in Servlets?

2 Answers   Wipro,


can we override service method in my servlet class..?? if yes or no why ??

7 Answers   IBM,


What methods do we use in Servlet to Applet communication?

3 Answers   Infosys,






Categories