返回信息流我自己编写了一个web项目在里面写了一个GossipListener的监听器,代码如下:
package cc.openhome.listener;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import cc.openhome.model.information.GmailCarrier;
@WebListener
public class GossipListener implements ServletContextListener {
private ServletContext context = null;
public GossipListener() {
}
public void contextInitialized(ServletContextEvent sce) {
try{
context=sce.getServletContext();
Properties props=new Properties();
props.load(context.getResourceAsStream("/WEB_INF/mail.properties"));
GmailCarrier carrier=new GmailCarrier(props);
//设为全局的共享变量
context.setAttribute("GmailCarrier", carrier);
System.out.println("wwwwwwwwwwwwwwwwwwwwww");
}catch(Exception e)
{
}
}
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
System.out.println("The Simple Web App. Has Been Removed");
this.context = null;
}
}
不知道为什么,每次启动Tomcat服务器,服务器的控制台并没有输出wwwwwwwwwwwwwwwwwwwwww这句话。 我自己修改了代码,在保存,控制台输出了The Simple Web App. Has Been Removed这句话。
我自己的这个web工程,其他的servlet访问这个共享变量,值是null。不知道为什么啊,求大神指点!
这是一条镜像帖。来源:北邮人论坛 / www-technology / #25429同步于 2014/5/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
WWWTechnology机器人发帖
ServletContextListener监听器问题
AAAMWAAA
2014/5/6镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。