I want to do something similar to this --
I have ten database queries that run. As each query finishes I want the
client to see on his browser the result of the query. Is this possible???
I was trying to use the output streams and flush them, but that doesn't seem
to do anything; the client only sees ALL the results after the page has been
built.
How can I force the flush all the way back to the client's browser?
Thanks
Kjersten
below is the code I call after each query is built(_countMe is just an int
for debugging):
public void writeToPage(String stringToWrite)
{
CSpider.putAnyUserSessionObject("soStatusNow",stringToWrite);
load("ADMIN.pgStatusNow");
CSpLog.send(this, CSpLog.ERROR, "writeToPage: "+ _countMe +" Text
to write:" + stringToWrite);
spider.util.CSpStringOutputStream _origStream = null;
ByteArrayOutputStream _myArrayStream = null;
CSpStringOutputStream _myStream = null;
// Save the original output stream
_origStream = CSpider.getOutputStream ();
// Construct a byte array output stream and create a
// CSpStringOutputStream out of it
_myArrayStream = new ByteArrayOutputStream (10000);
_myStream = new CSpStringOutputStream (_myArrayStream);
// Set our temporary string output stream to be used
// when constructing the HTML ("stealing" the HTML page)
CSpider.setOutputStream (_myStream);
try
{
// Flush everything so that our byte array will get loaded
// with the HTML
CSpHtml.flush (_myStream);
// Convert the byteArray into a String
String htmlPage = _myArrayStream.toString ();
// Restore the original output stream
CSpider.setOutputStream (_origStream);
String modifiedHtmlPage = "Content-type: text/html
<HTML><HEAD></HEAD><BODY>"+stringToWrite+_countMe+"</BODY></HTML>";
_countMe = _countMe + 1;
CSpHtml.sendRawDataItem (_origStream, modifiedHtmlPage);
//CSpHtml.flush(_origStream);
//spider.html.CSpHttp.flush(_origStream);
//spider.html.CSpHtml.writeHtmlDataBuffer(_origStream,false) ;
// flush stream
//CSpHtml.flush (_origStream);
// uncomment to clear all html before write
//CSpHttp.reset ();
// uncomment to clear all html before write
//CSpHttp.setAutoMode (false);
// write to web server output stream
//origStream.write(new String(buff,0));
//flush output stream
_origStream.flush();
}
catch (Exception ex)
{
// Shouldn't occur
}
}