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
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 |
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 |
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 |
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 |
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 |
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 |
What is with the javax.servlet package naming?
List out difference between a JavaBean from a Servlet?
What are the different types of servlets?
What is SingleThreadModel interface?
Can a servlet be called by passing its name as a parameter in the URL?
How can the referrer and the target urls be used in servlet?
Can we refresh servlet in client and server side automatically?
What is the use of send redirect () method?
What is the difference between servlet config and servlet context.
19 Answers TCS, Tech Mahindra, Vertex,
explain filters in java?
What do you mean by singlethreadmodel interface?
waht is the main diference b/w servelts and JSP ?