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
How do we go with database connection and log4j integration in servlet?
What is servlet interface?
What is the use of java servlet api?
Can we fetch the attributes related to a servlet on a different servlet?
How to get the path of servlet in the server?
Explain servlet.
What is servlet and its types?
Which method of the httpservletrequest object is used?
Is servlet a server side scripting language?
How is a servlet implemented in code?
Which interface should be implemented by all servlets?
What are session variable in servlets?
Name the packages that work with servlet?
How to generate the server side programming and the advantages of it over the other languages?
How to get the IP address of client in servlet?