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

How do you invoke a servelt?

0 Answers  


how to make the IP address to .com

1 Answers   iGate,


What is the process to implement doget and dopost methods?

0 Answers  


How do cookies work in servlets?

0 Answers  


What is api in servlet?

0 Answers  






What are the life cycle methods of the servlet?

0 Answers  


What is servlet initializer?

0 Answers  


How servlet is created?

0 Answers  


i have 500 jsp in my application ,with same forward name,it lokks for appropritae jsp from 1 to 500,but i want to send response to 498 page,what should i do

2 Answers   Caritor, Globerian,


How to get the current httpsession object?

0 Answers  


can we create more than ServletContext and ServletConfig in your application

6 Answers   Patni,


Explain get and post.

0 Answers  


Categories