ServletConfig and ServletContext
Both ServletConfig and ServletContext are configuration objects used by servlet container to initialize various init parameters for a web application. However they differ in terms of the scope and availability of init parameters defined by both of them ServletConfig The parameter scope is limited to the scope of the servlet in which the parameter is defined. For example, shopping cart of a user is specific to a particular user so servletconfig params can be used. One ServletConfig per servlet It is used to pass deploy-time info to servlet and configured in the deployment descriptor file. It is used to access ServletContext It is within the Servlet element in Deployment descriptor. It is accessed by using getServletConfig().getInitParameter("myname"); It is available only to the servlet in which init-param is configured. <servlet> <display-name>InitParamTest</display-name> <servlet-name>InitParamTest</servlet-name> ...