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
What is meant by cookies?
What are the functions of Servlet container?
How can we perform any action at the time of deploying the project?
Can a jsp be called using a servlet?
What are life cycle methods of a servlet?
What is a servlet-to-servlet communcation?
What are the types of an http request?
What are the servlet events?
Can we refresh servlet in client and server side automatically?
What is generic servlet class?
What are the objects involved when a servlet receives a call from client?
What are the life-cycle methods for a servlet?
Which method of the httpservletrequest object is used?
Why is httpservlet declared abstract?
Does servlet have main method?