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


Please Help Members By Posting Answers For Below Questions

Define the servlet mapping.

540


Explain load on start-up and its importance?

582


How do servlets work?

524


What is Client-Server Computing?

1885


Explain mvc pattern.

582






Difference between doget and dopost?

672


What is servlet in simple terms?

555


What is context in servlet?

531


What is the inter-servlet communication?

687


What is the difference between forward () and sendredirect () functions in servlet? Explain

534


What do you mean by cgi and what are its drawbacks?

520


What is the use of welcome-file-list?

560


What are all the ways for session tracking?

584


What are the important functions of filters?

584


What is the use of request dispatcher interface?

559