Posted in: Servlets FAQs
- ServletConfig a ServletConfig object is used to obtain configuration data when it is loaded.
- There can be multiple ServletConfig objects in a single web application.
- This object defines how a servlet is to be configured is passed to a servlet in its init method.
- Most servlet containers provide a way to configure a servlet at run-time (usually through flat file) and set up its initial parameters.
- 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);
}