新手求助:实时变量的读取和显示问题
在web上显示一个实时变量应该怎么做?下面是我的尝试,没有成果,求大神指出问题或者推荐个正确方法
用一个servlet读取一个实时变量,把这个sevlet写在webxml里的loadon上,然后在这个servlet的int里写循环读取变量,然后把变量赋值到application中,结果在web上显示是null(变量已经读取到),求助为什么,是不是我根本方法上就错误?求助各位大神!!
public void init(ServletConfig config) throws ServletException {
tring[] sr = connectDcs.fLog();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
String content = "1\r\ngkl";
String result = connectDcs.fRead(sr,content);
System.out.println(result);
ServletContext application = getServletContext();
application.setAttribute("gkl",result);
}
}, 0, 1000);
}