What is ServletContext() and what is its use?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is cookie? Why is cookie used?

594


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

595


Can we override servlet service method?

593


What's the use of servletcontext?

690


What methodology can be followed to store more number of objects in a remote server?

1825






What are the various ways of session supervision in servlets?

531


why we should override only no-agrs init() method.

686


When is the servlet instance created in the life cycle of servlet? What is the importance of configuring a servlet?

587


What is servlet invoker?

605


Explain the role of dispatcherservlet and contextloaderlistener.

614


Explain the steps involved in placing a servlet within a package?

576


Tell the new features added in servletrequest interface i.e. Servlet 2.4

584


Write a command to get actual path of a servlet to the server?

547


Is servlet a controller?

581


How many servlet objects are created?

572