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
Define the lifecycle for executing a jsp page.
Explain how does JSP handle run-time exceptions?
What is a deployment descriptor?
What is session tracking?
what is the different between a servlet and a cgi? Why do you go for servlet rather than cgi?
How can you push data from an Applet to a Servlet?
Explain the working of service() method of a servlet.
Describe the phases of servlet lifecycle?
What is the difference between jsp and servlet life cycle?
How do you deal property files in servlet?
What are the key methods that are involved in processing of http servlets?
How to generate the server side programming and the advantages of it over the other languages?
List some life cycle methods of a servlet.
What is servlet and its life cycle?
Should I override the service() method?