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
A client sends requests to two different web components. Both of the components access the session. Will they end up using the same session object or different session ?
What is meant by Servlet? What are the parameters of service method?
What is session tracking?
Explain the architechure of a servlet?
Which HTTP method is non-idempotent?
Why doesn’t a servlet include main()? How does it work?
Is servlet a framework?
What methodology can be followed to store more number of objects in a remote server?
What is the difference between the include() and forward() methods?
Explain jsessionid?
The code in a finally clause will never fail to execute, right?
What is getservletcontext?
Is servlet a controller?
What is http servlet in java?
Can you create a deadlock condition on a servlet?