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
Given the request path below, which are context path, servlet path and path info?
What’s the use of the servlet wrapper classes??
What is the purpose of inter-servlet communication?
What is preinitialization of a servlet?
Explain the jar and war files in servlet?
What are the various ways of session supervision in servlets?
Describe the phases of servlet lifecycle?
What is the difference between the getrequestdispatcher(string path) method of javax.servlet.servletrequest interface and javax.servlet.servletcontext interface?
How can a servlet be used to generate plain text instead of html?
How can we create deadlock situation in servlet?
What is the disadvantage of cookies?
What is servlet in tomcat?
What is meant by cookies?
What is a cookie What is the difference between session and cookie
What is the difference in between the httpservlet and generic servlet?