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
Which application server is best for java?
Explain in brief the directory structure of a web application?
What is the use of servletconfig interface?
Is servlet a server side scripting language?
Why filter is used in servlet?
What is servlet and how it works?
What are the phases of servlet life cycle?
What is servlet collaboration?
What’s the use of the servlet wrapper classes??
What are the different methods of session management in servlets?
What do you mean by cgi and what are its drawbacks?
Why HttpServlet class is declared abstract?
Where do you define dispatcherservlet?
Elucidate servlet attributes and its scope?
Which protocol will be used by browser and servlet to communicate