Explain about ServletConfig Interface ?

  1. ServletConfig a ServletConfig object is used to obtain configuration data when it is loaded. 
  2. There can be multiple ServletConfig objects in a single web application.
  3. This object defines how a servlet is to be configured is passed to a servlet in its init method. 
  4. Most servlet containers provide a way to configure a servlet at run-time (usually through flat file) and set up its initial parameters. 
  5. The container, in turn, passes these parameters to the servlet via the ServetConfig.


TestServlet
TestServlet

driverclassname
sun.jdbc.odbc.JdbcOdbcDriver


dburl
jdbc:odbc:MySQLODBC




public void init()
{
ServletConfig config = getServletConfig();
String driverClassName = config.getInitParameter("driverclassname");
String dbURL = config.getInitParameter("dburl");
Class.forName(driverClassName);
dbConnection = DriverManager.getConnection(dbURL,username,password);
}



Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email