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

what is session tracking?what are types of session tracking ?and when to cookies,when to use sessionmanagement,whent use url rewriting technique,plz explain briefly?

6 Answers   Satyam, TCS,


What is meant by a web application

0 Answers  


What is the difference between the include() and forward() methods?

0 Answers  


how do you maintain sessions in servlets?

5 Answers   AZTEC, L Cube,


Why do you use session tracking in httpservlet?

0 Answers  






Explain how to improve Servlet Performance?

0 Answers   BirlaSoft,


How to set a cookie that is persisted only for the duration fo the clients session?

1 Answers  


What is difference between PrintWriter and ServletOutputStream?

0 Answers  


What are the ways to handle multi-threading in servlets?

0 Answers  


What is the procedure of invoking different servlet in a different application?

0 Answers  


What is the use of RequestDispatcher in servlet?

18 Answers   Accenture, CTS, TCS,


how to use servlets with j2ee ?

2 Answers   Tech Mahindra,


Categories