----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------


I have a working servlet that output little chunks of html while a long
query is happening; I know it works, I can see the packets going
back to the browser with tcpdump.  Possibly you could post some
sample code that doesn't work?

Here's a servlet snippet that does flush as it goes (prints a line
every second).  This works on JServ 1.2 JDK 1.2.2 Solaris 2.7 apache 1.3.12:

        PrintWriter out = null;
        Vector args = getPathInfoArgs(req);
        int sleepMS = 1000;

        if (args.size() > 0) {
            String sleepTime = (String)args.elementAt(0);
            sleepMS = Integer.parseInt(sleepTime);
        }

        res.setContentType("text/plain");
        out = new PrintWriter(res.getOutputStream()); 
        int count = 30;
            
        try {
          while (count-- > 0) {
            Thread.sleep(sleepMS);
            out.println("Slept for " + sleepMS + " ms.");
            out.flush();
          }
        } catch (InterruptedException e) {
            out.println("Interrupted!");
        }

        out.close();

good luck.

billo


    From: Martin Naskovski <[EMAIL PROTECTED]>
    Date: Wed, 18 Oct 2000 16:22:22 -0700
    
    ----------------------------------------------------------------
    BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
    WHEN YOU POST, include all relevant version numbers, log files,
    and configuration files.  Don't make us guess your problem!!!
    ----------------------------------------------------------------
    
    And I would like to add that I do properly close() the output stream at the 
    end of the doPost/doGet, and at that time I do get output, provided the 
    browser hasnt timed out on me, however, that is not what I want. I would 
    like to FLUSH midway in doPost and be able to see the results up to that 
    point, or not even the results, I just want the TITLE of the page 
    displayed.  And out.flush() does not cut the mustard for this particular 
    purpose.
    
    Please help.
    
    Thank you in advance,
    Martin
    
    
    At 04:04 PM 10/18/2000 -0700, Martin Naskovski wrote:
    >----------------------------------------------------------------
    >BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
    >WHEN YOU POST, include all relevant version numbers, log files,
    >and configuration files.  Don't make us guess your problem!!!
    >----------------------------------------------------------------
    >
    >I have a problem flushing a servlet's output with out.flush(). Using 
    >out.flush() does not really do anything for me. Here's why -
    >
    >when the servlet's initially loaded (in IE5.5), it is loaded by calling 
    >GET (doGet method) (of course). On that screen, I have a <FORM..., which 
    >is then POST-ed to the same servlet, and doPost is supposed to take over 
    >the input data from the user for further processing.
    >
    >Once the user hits the "Submit" button on the initial (GET) page, and the 
    >servlet enters the doPost method, I run a really long MySQL query (about 4 
    >minutes) and by the time the query is done, my browser (IE 5.5) has timed 
    >out and the connection between the browser and the servlet is lost. 
    >Thusly, the user never sees the result set output in spite of the 
    >successfull completion of the mysql query.
    >
    >My question(s):
    >
    >- is there a way to keep the connection, once the user hits "Submit" and 
    >the servlet is in the doPost already, alive for an indefinite period of 
    >time? If yes, how is this done, through meta html headers, browser 
    >settings, apache jserv settings or what?
    >
    >or
    >
    >- is there a way to _force_ a flush once in the doPost() method? I do 
    >out.flush() _SEVERAL_ times in my doPost, but to no avail :(.  It just 
    >won't flush until the very end of the query, apparently right around the 
    >time out.close() gets called.   How is one supposed to be able to flush 
    >absolutely then? Should I use some other setContentType param, not 
    >"text/html"? Maybe some multipart mime type? What do I nede to do to truly 
    >force a flush while the 'globe's spinning' :), that is, my connection is 
    >still open?  After hitting submit, the connection is still open, waiting 
    >for output from the servlet, and INDEED there is output, but it's not 
    >flushed! Why??? Anyone an expert on jserv?
    >
    >- I've heard of using the "Refresh" meta header tag, but won't that 
    >re-issue another GET to the servlet and basically screw everything up ?
    >
    >Has anyone been in a similar situation with servlets?  I'm a little 
    >confused about how the flush works.
    >
    >We run JSDK2.0, and
    >
    >Can someone with more expertise please clairfy? I've also read the FAQ on 
    >this, but not much help there ("just run out.flush()").
    >
    >Thank you.
    >
    >Martin
    >
    >
    >
    >--
    >--------------------------------------------------------------
    >Please read the FAQ! <http://java.apache.org/faq/>
    >To subscribe:        [EMAIL PROTECTED]
    >To unsubscribe:      [EMAIL PROTECTED]
    >Search Archives: 
    ><http://www.mail-archive.com/java-apache-users%40list.working-dogs.com/>
    >Problems?:           [EMAIL PROTECTED]
    >
    
    
    
    --
    --------------------------------------------------------------
    Please read the FAQ! <http://java.apache.org/faq/>
    To subscribe:        [EMAIL PROTECTED]
    To unsubscribe:      [EMAIL PROTECTED]
    Search Archives: 
    <http://www.mail-archive.com/java-apache-users%40list.working-dogs.com/>
    Problems?:           [EMAIL PROTECTED]
    
    


--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search Archives: 
<http://www.mail-archive.com/java-apache-users%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to