Is there any differance b/w getting servlet context from
servlet config and session? if yes then what is that?

Answers were Sorted based on User's Feedback



Is there any differance b/w getting servlet context from servlet config and session? if yes then w..

Answer / nisha

Servlet config is one per servlet and servlet context is one for
the whole webapplication.

Servlet config is used to pass deploy time information to servlet
where servlet context can be used to get information about the
container,server.

Is This Answer Correct ?    13 Yes 4 No

Is there any differance b/w getting servlet context from servlet config and session? if yes then w..

Answer / sandhya

YES,There is some difference,when we deploy the web
application the web container will create the Context
object and when we load the servlet class then container
will create config object,so for each web application web
container will create one servlet context obj and for each
servlet web container will create servlet config object.

Generally we use this objects to avoid the hardcoding,we
declare this variables in deployment descriptor,we declare
context parameters under web-app tag so that all servlets
can use this parameter values ,and config parameters under
servlet tag so that only specific servlet can use this
parameter values,in simple way context object is like
global object and config obj is like local obj.

Is This Answer Correct ?    8 Yes 3 No

Is there any differance b/w getting servlet context from servlet config and session? if yes then w..

Answer / frank tamaguchi

The ServletContext returned from ServletConfig and from
HttpSession are the same instance, the one instance that
exists while the web application is running. You can confirm
it with a debugger.

The main differences though are that you get a reference to
ServletConfig when in a Servlet and you get a reference to
an HttpSession from an HttpServletRequest.

You can get a reference to a ServletContext from a
FilterConfig when in a Filter.

If you are not in a Servlet and don't want to create an
HttpSession through a call to
HttpServletRequest.getSession() to be able to get a
reference to a ServletContext then create a Filter which
puts a reference to the ServletContext in a request attribute.

Is This Answer Correct ?    3 Yes 1 No

Is there any differance b/w getting servlet context from servlet config and session? if yes then w..

Answer / rajendra singh bisht

You can get reference to ServletContext through ServletConfig. HttpSession does not provide a reference to ServletContext object.

To get a ServletContext object use

getServletConfig().getServletContext();

or you can call directly getServletContext() bcoz GenericServlet class implements ServletConfig interface also.

Is This Answer Correct ?    4 Yes 3 No

Is there any differance b/w getting servlet context from servlet config and session? if yes then w..

Answer / katamraju

Yes, some difference is there b/w servletconfig , servlet
context and session.
ServletContext:This is an interface created by webcontainer
based on class provided by webcontainer wendor,the
webcontainer will be create ServletContext Obj for the whole
web-application.
ServletConfig:This also an inteface and created by
webcontainer based on class provided by webcontainer vendor,
webcontainer creates servlet config obj forevery resource
that is available in webapplication.
session:session can be used to develop stateful application.

Is This Answer Correct ?    3 Yes 3 No

Is there any differance b/w getting servlet context from servlet config and session? if yes then w..

Answer / thennavan.m

YES.

ServletContext(): To communicate with the Servlet Container.
Eg: What server to running on the
Environment.Then when sever is
started,who is login the server all
the information to store the
"Event log"file ie log4j.

ServletConfig(): Pass the configuration information to the
Server to the servlet.

Session(): Session is a Object to track
the user interaction with
the web application across multiple
HttpSession.

Is This Answer Correct ?    0 Yes 0 No

Is there any differance b/w getting servlet context from servlet config and session? if yes then w..

Answer / koti

servlet context:servletcontext is only one web web
application object
servlet config: servlet config is multiple object in
webapplication

Is This Answer Correct ?    9 Yes 13 No

Post New Answer

More Servlets Interview Questions

What is the process to implement doget and dopost methods?

0 Answers  


What are the steps involved in placing a servlet within a package?

0 Answers  


Can we define constructor in Servlet class?

10 Answers   Accenture, Yugma,


Which method the Servlet container call to create the instance of the servlet?

16 Answers   emc2, JK Technosoft,


can i override service method

3 Answers   Intelligroup,






What is a cookie What is the difference between session and cookie

0 Answers  


Why are servlets used?

0 Answers  


can i call init() method in destroy() method of servlset. ?

5 Answers   IBM,


If a servlet is not properly initialized, what exception may be thrown?

0 Answers  


we cant Override Jsp Service method?Why?

4 Answers   Infrasoft, Mind Tree,


describe all about advanced java with presentation

4 Answers   Sun Microsystems,


Can you create a deadlock condition on a servlet?

0 Answers  


Categories