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

Define the lifecycle for executing a jsp page.

599


Explain how does JSP handle run-time exceptions?

586


What is a deployment descriptor?

603


What is session tracking?

700


what is the different between a servlet and a cgi? Why do you go for servlet rather than cgi?

575






How can you push data from an Applet to a Servlet?

612


Explain the working of service() method of a servlet.

508


Describe the phases of servlet lifecycle?

634


What is the difference between jsp and servlet life cycle?

693


How do you deal property files in servlet?

606


What are the key methods that are involved in processing of http servlets?

630


How to generate the server side programming and the advantages of it over the other languages?

565


List some life cycle methods of a servlet.

592


What is servlet and its life cycle?

574


Should I override the service() method?

672