Container passes the ServletConfig to the init() method of the Servlet at the initialization time. But how the container pass the ServletContext to which servlet's which method, because it is a application based? I mean how container initialize ServletContext?
So whenever you want to use ServletContext init parameter in your Servlet you have to initialize the Servlet by running it's init(ServletConfig) method. If container already initialized the Servlet (which needs ServletContext init parameter)then you can access ServletContext init parameter directly.Correct me if I am wrong.
you have to initialize the Servlet by running it's init(ServletConfig) method.
How would you do that ? Where would you take the ServletConfig from ? No, the container calls the init method. You can't use the ServletContext until the servlet has been initialized by the container.
Whenever you want ServletContext init parameter container first initialize the Servlet, so you get ServletConfig then you get ServletContext init parameter. Correct me if I am wrong.
When web app is loaded in memory by container by using web.xml of the app , servletContext Object is created and becomes avaible to all servlets and JSPs in the app. Now when a servlet is loaded in memory by container, it creates ServletConfig object and pass it to the servlet. This object contains the ServletContext Object.
I have one doubt here. Servlet Context is common to all servlets. Servlet Config is per servlet. In that case how the Servlet Context is inside the Servlet Config?
What prevents you(ServletConfig) and I(ServletConfig) from using the same train(ServletContext) ? The train doesn't care who's riding in, but you know which train you're using, don't you ? Does it make sense to make ServletContext accessible from the ServletConfig ?