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

Which method of the httpservletrequest object is used?

663


What is api in servlet?

617


What is the directory structure of a war file?

788


How do you create a cookie using servlet?

675


What is the use of welcome-file-list?

645






What does the term localization refer to?

666


How is an application exception handling is done using a servlet?

618


What are different Authentication options available in Servlets.

657


Can you refresh servlet in client and server-side automatically?

718


What is http servlet? Explain with the help of an example.

661


What is load-on-startup in servlet?

664


What is the advantage of Servlets when compared with other server side technologies?

1952


Where do you define dispatcherservlet?

627


Why servlet is used as controller ? Not JSP? I want complete explation?

757


Tell us something about servletcontext interface.

696