我想根据前台JSP输入来设置该类中task1的开始运行时间time1,请问这个class如何修改为servlet?求教import java.net.*;
import java.io.*;
import java.util.*;public class SMStest {
public static void main(String args[])
throws java.io.IOException { TimerTask task1 = new TimerTask() {
public void run() { System.out.println("task1准备发送短信"); try
{
//指向NOWSMS短信服务的URL,GB2312简体中文编码
URL sms1 = new URL("http://127.0.0.1:8800/?PhoneNumber=+86139xxxx1358&Text=SMS测试&charset=GB2312" );
InputStream in1 = new BufferedInputStream(sms1.openStream( ));
System.out.println("sms1发送完毕");
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}//end Run
};//end task1
Timer timer1 = new Timer(); //控制时间,根据前台JSP页面输入而确定
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,12);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 0);
Date time1 = calendar.getTime(); timer1.schedule(task1,time1,1000);//定时发送
System.out.println("Press ENTER to stop the task");
System.in.read(new byte[10]);
timer1.cancel(); System.out.println("短信发送终止");
}
}
import java.io.*;
import java.util.*;public class SMStest {
public static void main(String args[])
throws java.io.IOException { TimerTask task1 = new TimerTask() {
public void run() { System.out.println("task1准备发送短信"); try
{
//指向NOWSMS短信服务的URL,GB2312简体中文编码
URL sms1 = new URL("http://127.0.0.1:8800/?PhoneNumber=+86139xxxx1358&Text=SMS测试&charset=GB2312" );
InputStream in1 = new BufferedInputStream(sms1.openStream( ));
System.out.println("sms1发送完毕");
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}//end Run
};//end task1
Timer timer1 = new Timer(); //控制时间,根据前台JSP页面输入而确定
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,12);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 0);
Date time1 = calendar.getTime(); timer1.schedule(task1,time1,1000);//定时发送
System.out.println("Press ENTER to stop the task");
System.in.read(new byte[10]);
timer1.cancel(); System.out.println("短信发送终止");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货