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 are the drawbacks of cgi?

572


What are important features of Servlet 3?

599


What are the supporting protocol by HttpServlet ?

659


What is the difference between context parameter and context attribute?

535


What are the types of servlet?

669






Explain jsessionid and when is it created?

597


Explain their methods? Tell me their parameter names also have you used threads in servlet?

585


What is the disadvantage of cookies?

580


What is setattribute in servlet?

558


What is servlet in simple terms?

574


Once the destroy() method is called by the container, will the servlet be immediately destroyed? What happens to the tasks(threads) that the servlet might be executing at that time?

777


What is the process to implement doget and dopost methods?

548


What are the uses of servlet

635


How can we implement a jsp page?

632


Whats the advantages using servlets over using CGI?

590