Greetings-
I have a web application that has a form that triggers a server process that
I would like to provide a "Searching. .." page for.
My strategy was to send the browser the "top half" of a web page, including
an animated "Searching. .." gif. I write the contents of this page to the
HttpServletResp onse output, and then flush the buffer (which I had thought
would cause the bytes written thus-far to make their way to the client). I
then do the time-intensive operation on the server side (simulated below
with a 10 second Thread sleep), followed by streaming to the output the
"bottom half" of the web page, including a META refresh that would cause the
client to redirect to a "Results" page.
Unfortunately, what actually happens is that the client (IE 6) waits until
the entire page is sent, briefly shows the "Searching. .." image, and then
immediately redirects to the "Results".
I have tried explicitely setting the bufferSize of the response to be
smaller than the length of the "top half", but this didn't seem to alter the
behavior.
I am serving from Tomcat 5.0.16, which I'm beginning to suspect might be a
culprit here, somehow micro-managing the buffer until the servlet returns
from processRequest( ), thus thwarting my flushBuffer( ) strategy.
Below is the processRequest( ) method of my Servlet. Below that are the two
halves of the web page. I have removed some domain-specific names and
modified slightly for readability.
Thanks in advance for any insight!
-Eric
void processRequest( HttpServletRequ est request, HttpServletResp onse
response) throws ServletExceptio n, IOException
{
response.setHea der("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
response.setHea der("Cache-Control", "no-cache, must-revalidate");
response.setHea der("Pragma", "no-cache");
BufferedInputSt ream inStreamA = null;
BufferedInputSt ream inStreamB = null;
BufferedOutputS tream outStream = null;
try
{
response.setCon tentType("text/html");
outStream = new BufferedOutputS tream(response. getOutputStream ());
File fileTop = new File(FILE_TOP);
long halfFileSize= fileTop.length( )/2;
response.setBuf ferSize(((int)h alfFileSize));
inStreamA = new BufferedInputSt ream(new FileInputStream (fileTop));
int byteRead = inStreamA.read( );
while (byteRead != -1)
{
outStream.write (byteRead);
byteRead = inStreamA.read( );
}
outStream.flush ();
response.flushB uffer();
try { Thread.sleep(10 000); }
catch (InterruptedExc eption ignored) { }
inStreamB = new BufferedInputSt ream(new
FileInputStream (FILE_BOTTOM));
byteRead = inStreamB.read( );
while (byteRead != -1)
{
outStream.write (byteRead);
byteRead = inStreamB.read( );
}
outStream.flush ();
response.flushB uffer();
}
catch(Exception e)
{
log.log("proble m : " + e);
}
finally
{
if (inStreamA != null)
{
inStreamA.close ();
}
if (inStreamB != null)
{
inStreamB.close ();
}
}
}
==========TOP FILE=========== =
<html>
<head>
<title>Searchin g</title>
</head>
<body>
<img src="images/searching.gif" border="0">
=============== ===============
==========BOTTO M FILE=========
<META http-equiv=refresh content="0;URL= results.html">
</body>
</html>
=============== ===============
I have a web application that has a form that triggers a server process that
I would like to provide a "Searching. .." page for.
My strategy was to send the browser the "top half" of a web page, including
an animated "Searching. .." gif. I write the contents of this page to the
HttpServletResp onse output, and then flush the buffer (which I had thought
would cause the bytes written thus-far to make their way to the client). I
then do the time-intensive operation on the server side (simulated below
with a 10 second Thread sleep), followed by streaming to the output the
"bottom half" of the web page, including a META refresh that would cause the
client to redirect to a "Results" page.
Unfortunately, what actually happens is that the client (IE 6) waits until
the entire page is sent, briefly shows the "Searching. .." image, and then
immediately redirects to the "Results".
I have tried explicitely setting the bufferSize of the response to be
smaller than the length of the "top half", but this didn't seem to alter the
behavior.
I am serving from Tomcat 5.0.16, which I'm beginning to suspect might be a
culprit here, somehow micro-managing the buffer until the servlet returns
from processRequest( ), thus thwarting my flushBuffer( ) strategy.
Below is the processRequest( ) method of my Servlet. Below that are the two
halves of the web page. I have removed some domain-specific names and
modified slightly for readability.
Thanks in advance for any insight!
-Eric
void processRequest( HttpServletRequ est request, HttpServletResp onse
response) throws ServletExceptio n, IOException
{
response.setHea der("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
response.setHea der("Cache-Control", "no-cache, must-revalidate");
response.setHea der("Pragma", "no-cache");
BufferedInputSt ream inStreamA = null;
BufferedInputSt ream inStreamB = null;
BufferedOutputS tream outStream = null;
try
{
response.setCon tentType("text/html");
outStream = new BufferedOutputS tream(response. getOutputStream ());
File fileTop = new File(FILE_TOP);
long halfFileSize= fileTop.length( )/2;
response.setBuf ferSize(((int)h alfFileSize));
inStreamA = new BufferedInputSt ream(new FileInputStream (fileTop));
int byteRead = inStreamA.read( );
while (byteRead != -1)
{
outStream.write (byteRead);
byteRead = inStreamA.read( );
}
outStream.flush ();
response.flushB uffer();
try { Thread.sleep(10 000); }
catch (InterruptedExc eption ignored) { }
inStreamB = new BufferedInputSt ream(new
FileInputStream (FILE_BOTTOM));
byteRead = inStreamB.read( );
while (byteRead != -1)
{
outStream.write (byteRead);
byteRead = inStreamB.read( );
}
outStream.flush ();
response.flushB uffer();
}
catch(Exception e)
{
log.log("proble m : " + e);
}
finally
{
if (inStreamA != null)
{
inStreamA.close ();
}
if (inStreamB != null)
{
inStreamB.close ();
}
}
}
==========TOP FILE=========== =
<html>
<head>
<title>Searchin g</title>
</head>
<body>
<img src="images/searching.gif" border="0">
=============== ===============
==========BOTTO M FILE=========
<META http-equiv=refresh content="0;URL= results.html">
</body>
</html>
=============== ===============
Comment