叶子树logo
首 页 技术教程 新闻资讯 网站展示 酷站欣赏 下载中心 站长故事 信息互动 论坛交流
Web www.webshu.net
 
  最新推荐→

 
  最新热门→

 
  相关文章→
 您现在的位置: 叶子树 >> 技术教程 >> 网络编程 >> JSP教程 >> 正文

JSP编程进度条设计实例(2)

作者:佚名    文章来源:不详    点击数:    更新时间:2008-4-28           

 

<% if request("infoid")<>"" then set rs=conn.execute("select * from nproduct where id="&request("infoid")) if not (rs.eof and rs.bof) then proname=rs("proname") content=rs("proinfo") end if rs.close set rs=nothing end if %>

  如果任务已经启动,isStarted()方法将返回true:


public synchronized boolean isStarted() {
    return started;
}
 


  如果任务已经完成,isCompleted()方法将返回true:


public synchronized boolean isCompleted() {
    return counter == 100;
}
 


  如果任务正在运行,isRunning()方法将返回true:


public synchronized boolean isRunning() {
    return running;
}



  SetRunning()方法由start.jsp或stop.jsp调用,当running参数是true时。SetRunning()方法还要将任务标记为“已经启动”。调用setRunning(false)表示要求run()方法停止执行。


public synchronized void setRunning(boolean running) {
    this.running = running;
    if (running)
        started  = true;
}
 
  任务执行完毕后,调用getResult()方法返回计算结果;如果任务尚未执行完毕,它返回null:


public synchronized Object getResult() {
    if (isCompleted())
        return new Integer(sum);
    else
        return null;
}
 
  当running标记为true、completed标记为false时,run()方法调用work()。在实际应用中,run()方法也许要执行复杂的SQL查询、解析大型XML文档,或者调用消耗大量CPU时间的EJB方法。注意“繁重的任务”可能要在远程服务器上执行。报告结果的JSP页面有两种选择:或者等待任务结束,或者使用一个进度条。


public void run() {
    try {
        setRunning(true);
        while (isRunning() && !isCompleted())
            work();
    } finally {
        setRunning(false);
    }
}


叶子树:www.webshu.net
  • 下一篇文章:

  • 文章录入:webshu    责任编辑:webshu 
    叶子树(www.webshu.net)所有资料源于作者发布或网友推荐收集整理而来,仅供学习使用,版权归原作者所有,如有侵权,请您联系我们,我们将尽快更正。

      网友评论:(评论内容只代表网友观点,与本站立场无关!) 发表评论

    友情链接 | 留言互动 | 版权声明
    Copyright©All return the ye ze shu and www.webshu.net   
    本站广告服务请加QQ:904166(超越-激情)
    京ICP备05086028号  把"叶子树" 与你的好友一起分享!