What is ServletContext() and what is its use?

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which application server is best for java?

653


Explain in brief the directory structure of a web application?

655


What is the use of servletconfig interface?

642


Is servlet a server side scripting language?

659


Why filter is used in servlet?

611






What is servlet and how it works?

583


What are the phases of servlet life cycle?

680


What is servlet collaboration?

748


What’s the use of the servlet wrapper classes??

722


What are the different methods of session management in servlets?

614


What do you mean by cgi and what are its drawbacks?

617


Why HttpServlet class is declared abstract?

727


Where do you define dispatcherservlet?

627


Elucidate servlet attributes and its scope?

659


Which protocol will be used by browser and servlet to communicate

663