无进度条刷新获得服务器端数据并相应处理(2)
2008-02-23 09:39:15来源:互联网 阅读 ()
<body onLoad="
<%
String temp = "";
String temp1 = "";
String temp2 = "";
boolean needbreak = false;
String username;
while(true){//循环等待消息
Thread.sleep(1000);//线程暂停1秒
try{
MessageListener ml = (MessageListener)application.getAttribute("messagelistener");
User user = (User)session.getAttribute("user");//获得此用户
if(user.getUmessagenumber() > 0){
temp2 = "RefreshMiddle();";
user.setUmessagenumber(0);
session.setAttribute("user",user);
needbreak = true;
}
if(ml != null){
if(ml.hasNewMarqueeMessage()){
ml.NoNewMarqueeMessage();
temp1 = "RefreshRight();";
needbreak = true;
}
}
if(needbreak) {
temp = temp1 temp2 "RefreshSelf();";
application.setAttribute("messagelistener", ml);
GuardUtil.debug("刷新页面,显示消息");
break;
}
}
catch(Exception e){
Thread.currentThread().destroy();
}
System.out.println("listening ... ...");
}//end while
out.println(temp);
%>"> <!-- end body tag -->
</body>
</html>
这种方法实际上是发送一个请求,如果没有新消息,服务器不予返回,直到出现新消息,才给予返回,这就导致一个问题,在发送和接受之间这段时间,页面一直为白板,显示页面读取未完成状态,所以必须把这个页面放到一个框架中让其大小为0。并且,必须在用户退出,或者用户的session超时时,将此线程销毁,防止一直连接服务器,占用资源。
采用这种方式之后,由于涉及到线程,而通常Web服务器如tomcat等不推荐自己操作线程,可能因为采用这种方式的原因,服务器此线程总是无端停止,没有响应,于是,我接着查找,又有所发现,见参考文章(1),参考文章写的比较简略,下面我给出详细的实现方法。
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:求助——关于SOAP消息的发送
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
