// import log4j packages import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; public class SetupServlet extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
// first thing to do, is to set up the Driver that we might be using // in case of JDBCAppender try{ Driver d = (Driver)(Class.forName( "org.gjt.mm.MySQL.Driver").newInstance()); DriverManager.registerDriver(d); //加載JDBC驅動程序,當預備將日志記錄到數據庫的時候可以使用 }catch(Exception e){ System.err.println(e); }
// next load up the properties //啟動時從web.xml中獲得配置文件的信息 String props = config.getInitParameter("props");
System.err.println( "ERROR: Cannot read the configuration file. " + "Please check the path of the config init param in web.xml"); throw new ServletException(); } }