简体   繁体   English

如何从用户输入中设置Java Timer类的时间

[英]How to Set the time of java Timer class from User input

I have got the requirement to set the timer from user input.What basically is my requirement is.. 我有从用户输入设置计时器的要求。基本上我的要求是..

1.Design a jsp page with input fields to set the date and time of timer .. 1.设计一个带有输入字段的jsp页面,以设置计时器的日期和时间。

2.Take these input field values and set the date and time. 2.采用这些输入字段值并设置日期和时间。

3.Execute the timer on the newly set date and time.. 3.在新设置的日期和时间执行计时器。

Actually i need to trigger mail at particular date and time and these date and time will be dynamically changed from user side to interacting to the jsp page.If date and time has been changed then it should trigger timer on that particular date and time leaving last one.. 实际上我需要在特定的日期和时间触发邮件,并且这些日期和时间将从用户端动态更改为与jsp页面进行交互。如果更改了日期和时间,则应该在该特定的日期和时间触发计时器一..

Currently i have a java class with main method which contains timer with hard-coded date and time which i need to change and give this facility to user to set and time .. 目前,我有一个带有main方法的java类,其中包含带有带有硬编码日期和时间的计时器,我需要对其进行更改并将此功能提供给用户进行设置和计时..

Please guys help me how to get from jsp page and Use it in java timer class .. 请大家帮我如何从jsp页面获取并在java计时器类中使用它..

Also my application is web application using jsp,servlet and POJO file.. 我的应用程序也是使用jsp,servlet和POJO文件的Web应用程序。

Here is my java class code... 这是我的Java类代码...

public final class FetchMail extends TimerTask {

/** Construct and use a TimerTask and Timer. */
public static void main(String... arguments) {
    TimerTask fetchMail = new FetchMail();
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(fetchMail, getTomorrowMorning4am(), fONCE_PER_DAY);
}

/**
 * Implements TimerTask's abstract run method.
 */
@Override
public void run() {

    System.out.println("Fetching mail...");
}
private final static long fONCE_PER_DAY = 1000 * 60 * 60 * 24;

private static Date getTomorrowMorning4am() {

    Calendar date = Calendar.getInstance();
    date.set(
            Calendar.DAY_OF_MONTH, 14);
    date.set(Calendar.HOUR, 10);
    date.set(Calendar.MINUTE, 14);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date.getTime();
}
}

Thanks in advance.. 提前致谢..

a string representing the date should be sent from the client using that JSP page. 应该使用该JSP页面从客户端发送代表日期的字符串。

then in the server side you should convert this string to a Calendar object, see converting String to Calendar. 然后在服务器端,您应该将此字符串转换为Calendar对象,请参见将String转换为Calendar。 What is the easiest way? 最简单的方法是什么?

note that the client and server should have the same date format. 请注意,客户端和服务器应具有相同的日期格式。

btw, consider using http://www.joda.org/ instead of Clendar 顺便说一句,考虑使用http://www.joda.org/代替Clendar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM