Advanced Java (2160707)

BE | Semester-4   Winter-2018 | 20-11-2018

Q2) (b)

Explain difference between ServletConfig and ServletContext object.

Sr Servlet Config Servlet Context
1 ServletConfig object is one per servlet class ServletContext object is global to entire web application
2 Object of ServletConfig will be created during initialization process of the servlet Object of ServletContext will be created at the time of web application deployment
3 Scope: As long as a servlet is executing, ServletConfig object will be available, it will be destroyed once the servlet execution is completed Scope: As long as web application is executing, ServletContext object will be available, and it will be destroyed once the application is removed from the server
4 We should give request explicitly, in order to create ServletConfig object for the first time ServletContext object will be available even before giving the first request
5 In web.xml – tag will be appear under tag In web.xml – tag will be appear under tag