📄 resourceinitlistener.java
字号:
/**
* 作者: 佟劲纬 创建日期: 2006-1-10
*
* QQ: 532443423 Email: TJW_7@163.com
*/
package com.tjw.guestbook.listener;
import javax.servlet.*;
import com.tjw.guestbook.database.*;
import com.tjw.guestbook.model.*;
public class ResourceInitListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent init) {
ServletContext application = init.getServletContext();
String driverClass = application.getInitParameter("driverClass");
String jdbcURL = application.getInitParameter("jdbcURL");
ConDatabase dataSource = new ConDatabase();
try {
dataSource.setDriver(driverClass, jdbcURL);
application.setAttribute("dataSource", dataSource);
} catch(ClassNotFoundException e) {
e.printStackTrace();
}
UserRegisterBean userRegister = new UserRegisterBean();
userRegister.setDataSource(dataSource);
application.setAttribute("userRegister", userRegister);
GuestBookManagerBean gbmanager = new GuestBookManagerBean();
gbmanager.setDataSource(dataSource);
application.setAttribute("gbmanager", gbmanager);
}
public void contextDestroyed(ServletContextEvent destroy) {
ServletContext application = destroy.getServletContext();
application.removeAttribute("conDatabase");
application.removeAttribute("userRegister");
application.removeAttribute("GBManager");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -