08 January 2021

ServletConfig

  • Unique object per servlet                        
  • Used to provide init parameters to the servlet   
  • We can’t set attributes in ServletConfig object. 
  • web.xml is known as deployment descriptor.
  • In web.xml – <init-param> tag will be appear under <servlet-class> tag
  • It is an interface from javax.servlet package.
  • Object of ServletConfig will be created during initialization process of the servlet
  • This Config object is public to a particular servlet only
  • Object of ServletConfig is created by the Container itself at the time it creates a Servlet object. For every object of Servlet, the container creates, also an object of ServletConfig. 
  • Scope: As long as a servlet is executing, ServletConfig object will be available, it will be destroyed once the servlet execution is completed.
  • We should give request explicitly, in order to create ServletConfig object for the first time
  • It is used to communicate with the Servlet under execution. Even though, the container creates the ServletConfig object implicitly for its purpose, the Programmer can make use of the object in his code to read initialization parameters into the Servlet from web.xml file.
  • If the parameter values change, the web.xml file need not be compiled. At the time reading, whatever values exists in the web.xml file, with those values or parameters only the Servlet is initialized.
  • The getServletConfig() method of GenericServlet returns an object of ServletConfig.
  • It is specific for a Servlet. Other way to say, if 100 servlet objects are being executed in the container, 100 ServletConfig objects are also created implicitly used by the container to communicate with the Servlet.
  • When the container destroys the Servlet object, along with it its corresponding ServletConfig object also destroyed.
  • The method of ServletConfig object used to read is "String getInitParameter(String)".

No comments:

Post a Comment

Most views on this month