flush方法可以强制写入底层stream,,所以缓冲区不满也会输出不用则要等到满了再一起输出,,那样就没有动态效果了,

解决方案 »

  1.   

    一般情况下服务器上的jsp文件执行完成以后才会向客户端输出内容,使用out.flush()可以强制将当前执行完的内容返回给客户端进行显示,服务器端继续执行下面的语句。
      

  2.   

    使用out.flush()可以强制将当前执行完的内容返回给客户端进行显示
    以后也不要用这样的方法让内存跑光了
    你学过数据结构吗多看一看就明白了
      

  3.   

    我建议延迟的部分你可以用线程休眠得办法。
    <%
    for(int i = 0; i <= 10; i++){
       Thread.sleep(3000);//这里延迟3秒,当然延迟多少你可以自己估算控制。
        out.println("hello word" + "<BR>"); 
        out.flush(); 
       }
    %>
      

  4.   

    其实最理想的方式不是直接用JAVA完成,可以在页面上用JAVASCRIPT完成该功能,JAVA只提供需要输出的格式化数据
      

  5.   

    你可以想象一下,有一个储物间;
    现在将10个柜子搬进去,再搬出来(呵呵,这样好傻哦)
    有几种方法:
    1、一个柜子搬进去,然后立刻搬出来。
    2、10个柜子都搬进去,然后再搬出来。
    对于方法一,就是使用flush
      

  6.   

    为什么我编译时会出错
    class A 
    {
    public static void main(String[] args) 
    {
    for(int i=0;i<=10;i++)
    {
    Thread.sleep(3000);
         System.out.println("Hello World!");
    System.out.flush();
            }
    }
    }
    报错:---------- javac ----------
    A.java:8: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
    Thread.sleep(3000);
                                  ^
    1 error输出完成 (耗时 2 秒) - 正常终止
      

  7.   

    因为要执行thread.sleep()方法,必须要抛出InterruptedException异常,所以应该写成
    class A{
        public static void main(String[] args) throws InterruptedException{
    for(int i=0;i<=10;i++){
        Thread.sleep(3000);
        System.out.println("Hello World!");
        System.out.flush();
    }
        }
    }或者是
    class A{
        public static void main(String[] args){
    for(int i=0;i<=10;i++){
                  try{
      Thread.sleep(3000);
                  }
                  catch(InterruptedException e){
                  }
                  System.out.println("Hello World!");
                  System.out.flush();
             }
        }
    }