Servlet Tutorial


ServletConfig (one per SERVLET):

  • ServletConfig is an interface which is present in javax.servlet.* package.
  • The purpose of ServletConfig is to pass some initial parameter values, technical information (driver name, database name, data source name, etc.) to a servlet.
  • An object of ServletConfig will be created one per servlet.
  • An object of ServletConfig will be created by the server at the time of executing public void init (ServletConfig) method.
  • An object of ServletConfig cannot be accessed in the default constructor of a Servlet class. Since, at the time of executing default constructor ServletConfig object does not exist.
  • By default ServletConfig object can be accessed with in init () method only but not in doGet and doPost. In order to use, in the entire servlet preserve the reference of ServletConfig into another variable and declare this variable into a Servlet class as a data member of ServletConfig.
  • For example:

    class x extends HttpServlet

  • When we want to give some global data to a servlet we must obtain an object of ServletConfig.
  • web.xml entries for ServletConfig
        <param-name>Name of the parameter</param-name>
        <param-value>Value of the parameter</param-value>

For example:


The data which is available in ServletConfig object is in the form of (key, vlaue)