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

559


Can you call a jsp from the servlet?

537


What do you understand by mime type?

556


If servlet receives multiple requests, how many objects will it create?

819


What is the life cycle of a servlet?

773






What is the difference between forward () and sendredirect () functions in servlet? Explain

539


Whether we can get deadlock situation in servlets?

570


What exactly is a servlet?

537


Which event is fired at the time of session creation and destroy?

862


What is the use of attribute in servlets?

535


Write the code to get the server information in servlet.

560


What do you mean by request dispatcher in servlet? Also explain its methods.

603


Explain url encoding?

512


How we can get ip address of client in servlet?

530


Why do we use sendredirect() method?

540