What is ServletContext() and what is its use?

Answers were Sorted based on User's Feedback



What is ServletContext() and what is its use?..

Answer / shiva

One Servlet Context object will be created by the container
for one webapplication. That means all servlets can have a
scope to acess that context object. for example, let us
assume there 5 servlets are there in u r web application,
if u want to share same data to all servlets then we can
share that data using servlet context, because every
servlet can have interaction with that application
environment...

Is This Answer Correct ?    182 Yes 22 No

What is ServletContext() and what is its use?..

Answer / anjan

Assume that ServletContext is shared momeroy for all
servelts which are existed in a web application,

we can place an object on to the servletcontext, and that
can uses all other servlets which are exited in the web
application.

Is This Answer Correct ?    153 Yes 27 No

What is ServletContext() and what is its use?..

Answer / asif shahzad

1. ServletContext is a window by which a Servlet instance see its environment.

2. ServletContext defines some methods that a Servlet instance can use to communicate with Servlet Container. E.g. To dispatch request, Writing to a log file etc.

3. Servlet Container pass the ServletConfig object to the Servlet instance when calling init(ServletConfig config) method. ServletContext instance reference exist inside the ServletConfig object.

4. Each Web application has only one ServletContext instance. So its a singleton object. If an Servlet Container deploys multiple Apps, each App have its own ServletContext.

Is This Answer Correct ?    98 Yes 8 No

What is ServletContext() and what is its use?..

Answer / shyam

if u want to use any data which is common for all use and
common to all servlet ,that data can be specified as context
parameters in the web.xml as follows.
<context-param>
<param-name>city</param-name>
<param-value>bangalore</param-value>
</context-param>
web container collects data from web.xml and stores that in
servlet context objects as context parameters.
As a developer,you can collect that data form context object
as follows.
String ci=context.getIntParameters("city").
All the servlets will have only one servlet context object
and can be shared with all servlets running in the container.
i.e: one web application will have one servletcontext object.

Is This Answer Correct ?    53 Yes 3 No

What is ServletContext() and what is its use?..

Answer / a,srinivas rao

servletcontext is an object which contains the information
regarding all the servlets that are used in web application.
when ever user first do the deployment of the web
application on the server the web container instantiate a
servlet context object.the information in the servlet
context object is also passed to init method.

Is This Answer Correct ?    51 Yes 20 No

What is ServletContext() and what is its use?..

Answer / telo

Data saved in a ServletContext scope is shared by all
servlets and JSPs in the context. The data stored in the servlet
context is destroyed when the servlet context is destroyed.
//save and get an application-scoped value
getServletContext().setAttribute(“application-value”,
“shopping-app”);
value = getServletContext().getAttribute(“application-value”);

Is This Answer Correct ?    28 Yes 9 No

What is ServletContext() and what is its use?..

Answer / srikanth

ServletContext is called web application there would be one servlet context for entire web applicationthe .servlet context is used to get the context parameters specified in web.xml and also get the information of servlet engineand also request dispatcher object.

Is This Answer Correct ?    15 Yes 14 No

What is ServletContext() and what is its use?..

Answer / ranjit

as soon as the java web application is
deployed into web container ,the first
object that container create is
servletcontext
This object is only one per web application
Every web component of web application
share this unique object

Is This Answer Correct ?    1 Yes 0 No

What is ServletContext() and what is its use?..

Answer / rahul kumar

A servlete context is the directory in which the servlet
are deployed in the web server. Servlet that are executing
in the same server belong to the same context.

Is This Answer Correct ?    18 Yes 31 No

Post New Answer

More Servlets Interview Questions

What is the use of httpservletresponsewrapper?

0 Answers  


Explain the different ways for servlet authentication?

0 Answers  


What are the uses of servlets?

0 Answers  


How to pass session values from one servlet container to another servlet container? or how can we get session values of one container in another container?

6 Answers   IBM, Infosys, TCS,


java.lang.IllegalArgumentException: The path of an ForwardConfig cannot be null while working with struts it displayed pls very ungent

3 Answers   IBM,






What is servlet and its types?

0 Answers  


What is Single Threaded Model in Servlets? Explain this with an example?

10 Answers   Wipro,


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,


how JSP can extend servlet or interface ...?

3 Answers   IBM,


What is the difference between Server and Container?

0 Answers  


How do we share data using 'getservletcontext ()?

0 Answers  


Is classes folder is compulsory in web-inf/ even though u r deploying ur application with war file?

3 Answers   Bosch, Cognizant,


Categories