解决方案 »

  1.   


    public static void start_publish_scheduling(){
    Timer timer = new Timer();
    Calendar calendar = Calendar.getInstance();
    calendar.set(2014, 04, 9, 17, 16, 00);
    Date date = calendar.getTime();
    timer.schedule(new MyTask(), date);
    }
    static class MyTask extends java.util.TimerTask { @Override
    public void run() {
    System.out.println("----execute------");

    }
    }
      

  2.   


    schedule()不是应该还有第三个参数的吗?
      

  3.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。
      

  4.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。我自己写了一个带参数的sendmail()函数,是要run()里调用这个函数吗?  可是run()不能带参数啊。public class SendMail extends TimerTask{ public void sendMail(String info, String mailAddress,
    String remindTime) {

    String month = remindTime.substring(0, remindTime.indexOf("/"));
    String day = remindTime.substring(remindTime.indexOf("/")+1, remindTime.lastIndexOf("/"));
    String hour = remindTime.substring(remindTime.lastIndexOf(" ")+1, remindTime.indexOf(":"));
    String minute = remindTime.substring(remindTime.indexOf(":")+1, remindTime.lastIndexOf(""));

    int m = Integer.parseInt(month) - 1;
    int d = Integer.parseInt(day);
    int h = Integer.parseInt(hour);
    int mi = Integer.parseInt(minute);

    Date date = new Date();
    date.setMonth(m);
    date.setDate(d);
    date.setHours(h);
    date.setMinutes(mi); Properties props = new Properties();
    props.setProperty("mail.smtp.socketFactory.class",
    "javax.net.ssl.SSLSocketFactory");
    props.setProperty("mail.smtp.socketFactory.fallback", "false");
    props.setProperty("mail.smtp.port", "465");
    props.setProperty("mail.smtp.socketFactory.port", "465"); Session session = Session.getDefaultInstance(props, null);
    Message msg = new MimeMessage(session); Transport transport = null;

    System.out.println("从网页传回的时间格式:"+remindTime);

    String taskdate = ""; try {
    String msgBody = "您好:" + "\n\n" + taskdate + "\n\n您有日程安排:" + info;
    msg.setSubject("日程   -  温馨提醒"); msg.setText(msgBody); transport = session.getTransport("smtp");
    transport.connect("smtp.gmail.com", "",
    ""); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(
    mailAddress));

    msg.setSentDate(date); transport.sendMessage(msg, msg.getAllRecipients()); transport.close();
    } catch (MessagingException e) {
    e.printStackTrace();
    }
    } @Override
    public void run() {


    }
      

  5.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。
    public static void main(String[] args) {
           Timer timer = new Timer();
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, 04, 9, 17, 16, 00);
            Date date = calendar.getTime();
            timer.schedule(new SendMail(), date);
    }
    执行这个main方法会再2014.05.09 17:16:00调用你的run方法
      

  6.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。
    public static void main(String[] args) {
           Timer timer = new Timer();
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, 04, 9, 17, 16, 00);
            Date date = calendar.getTime();
            timer.schedule(new SendMail(), date);
    }
    执行这个main方法会再2014.05.09 17:16:00调用你的run方法
    run()方法里应该写些什么,我需要用servlet接收网页传回的内容作为邮件的内容。
      

  7.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。
    public static void main(String[] args) {
           Timer timer = new Timer();
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, 04, 9, 17, 16, 00);
            Date date = calendar.getTime();
            timer.schedule(new SendMail(), date);
    }
    执行这个main方法会再2014.05.09 17:16:00调用你的run方法

    这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?
      

  8.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。
    public static void main(String[] args) {
           Timer timer = new Timer();
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, 04, 9, 17, 16, 00);
            Date date = calendar.getTime();
            timer.schedule(new SendMail(), date);
    }
    执行这个main方法会再2014.05.09 17:16:00调用你的run方法

    我理解是这样的,按您写的,run()方法应该写在SendMail类里,在run()方法里应该调用发送邮件的方法sendMail()我的问题就是我通过servlet接收网页请求的数据,在servle里调用sendMail方法,怎么传给run()方法呢。
      

  9.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。
    public static void main(String[] args) {
           Timer timer = new Timer();
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, 04, 9, 17, 16, 00);
            Date date = calendar.getTime();
            timer.schedule(new SendMail(), date);
    }
    执行这个main方法会再2014.05.09 17:16:00调用你的run方法

    这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?
    我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。
      

  10.   

    你的需求不需要用的timer schedule啊,
    只需要前台网页传时间和内容到后台,把你在后台接受到的值传到你的SendMail()方法里不就行了么。
      

  11.   


    我的意思是通过timer把前台传来的时间传入schedule。比如说前台数据是16:00为提醒时间,那么我希望是在系统时间为16:00时发送提醒邮件。而通过message.setSentDate()方法设置的发送时间只是在邮件主题下面显示,邮件仍然是立即就发送出去了,而不是16:00才发送的。
      

  12.   


    我的意思是通过timer把前台传来的时间传入schedule。比如说前台数据是16:00为提醒时间,那么我希望是在系统时间为16:00时发送提醒邮件。而通过message.setSentDate()方法设置的发送时间只是在邮件主题下面显示,邮件仍然是立即就发送出去了,而不是16:00才发送的。
    你把前台的时间保存到数据库,把所有时间放到系统内存,再监听所有时间发送邮件。
      

  13.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。
    public static void main(String[] args) {
           Timer timer = new Timer();
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, 04, 9, 17, 16, 00);
            Date date = calendar.getTime();
            timer.schedule(new SendMail(), date);
    }
    执行这个main方法会再2014.05.09 17:16:00调用你的run方法

    这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?
    我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。 以前做过一次
      

  14.   


    schedule()不是应该还有第三个参数的吗?
    可以直接传一个日期。
    public static void main(String[] args) {
           Timer timer = new Timer();
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, 04, 9, 17, 16, 00);
            Date date = calendar.getTime();
            timer.schedule(new SendMail(), date);
    }
    执行这个main方法会再2014.05.09 17:16:00调用你的run方法

    这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?
    我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。 以前做过一次能发给我看看,借鉴一下吗?