用的是tomcat5.5,是不是在关闭tomcat时候自动销毁 ? 为什么我自己的类实现了
ServletContextListener事件检听器,可是他却没有调用contextDestroyed方法呢,
还是需要自己在程序中销毁 ? 请教高手
注:contextInitialized已经在tomcat启动时自动调用了,可是destroy却不知何时调
ServletContextListener事件检听器,可是他却没有调用contextDestroyed方法呢,
还是需要自己在程序中销毁 ? 请教高手
注:contextInitialized已经在tomcat启动时自动调用了,可是destroy却不知何时调
import java.util.*;
import bookBean.*;
import api.*;
import personBean.*;
import javax.servlet.*;
import javax.servlet.http.*;public class ContextConfig implements ServletContextListener
{
public void contextInitialized(ServletContextEvent sce)
{
ServletContext app = sce.getServletContext();
InputStream ips = app.getResourceAsStream("/WEB-INF/records/config.properties");
Properties props = new Properties();
try
{
props.load(ips);
}
catch (Exception e)
{
System.out.println(e);
}
String book = props.getProperty("book"),
person = props.getProperty("person"),
record = props.getProperty("record"),
admin = props.getProperty("admin"),
name = props.getProperty("name"),
password = props.getProperty("password");
Manageable manage = new Manage();
manage.load(book,person,record,admin);
boolean b = manage.setAdminister(name,password);
System.out.println(b ? "添加成功,帐号:" + name + "密码:" + password:"添加失败");
app.setAttribute("manage",manage);
}
public void contextDestroyed(ServletContextEvent sce)
{
ServletContext app = sce.getServletContext();
InputStream ips = app.getResourceAsStream("/WEB-INF/records/config.properties");
Properties props = new Properties();
try
{
props.load(ips);
}
catch (Exception e)
{
System.out.println(e);
}
String book = props.getProperty("book"),
person = props.getProperty("person"),
record = props.getProperty("record"),
admin = props.getProperty("admin");
Manageable manage = (Manageable)app.getAttribute("manage");
manage.save(book,person,record,admin);
}
}这是代码,目的是在结束时 取出context对象中的manage对象并调用其save方法将资料保存,已测试过save方法是正确的
contextDestroyed必须是合法关闭才可以,也就是说杀进程是不行的。
在调试环境下设置断点看看
谢谢大家了,我是非法关闭了刚才.顺便问一下,tomcat合法关闭除了ctrl+c还有什么办法?
点关闭按钮代码都不执行.