www.pudn.com > Javamail.rar > ContextListener.java


package com.digipower.automail.mailsender;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.digipower.automail.AutoMailConstants;

/**
 * 

Title:

*

Description: TestStruts

*

Copyright: Copyright (c) 2004

*

Company: foxconn

* @author conti * @version 1.0 */ public class ContextListener extends HttpServlet implements ServletContextListener { //Notification that the web application is ready to process requests private java.util.Timer timerSend = null; private java.util.Timer timerReceive = null; public void contextInitialized(ServletContextEvent event) { AutoMailConstants.BOOTDIR = event.getServletContext().getRealPath("/") + "\\upload\\";//set the real path of uploadfile System.out.print("Context:" + AutoMailConstants.BOOTDIR); timerSend = new java.util.Timer(true); timerSend.schedule(new MyTask(event.getServletContext()), 0, AutoMailConstants.MAIL_SEND_INTERATE); timerReceive = new java.util.Timer(true); timerReceive.schedule(new ReceiveTask(event.getServletContext()), 0, AutoMailConstants.MAIL_SEND_INTERATE); } //Notification that the web application is ready to process requests public void contextDestroyed(ServletContextEvent event) { timerSend.cancel(); timerReceive.cancel(); System.out.println("Timer Cancel"); } }