Sending huge data to client browser

Wednesday, 20 June 2007, 0:56 | Category : Internet, J2EE, Java, Technology
Tags :

If you want to pass huge data to the client from your servlet, user may need to wait till the ServletOutputStream or JSPWriter flushes the data. This happens generally whenever you have a number of items page and you want to pass it to the client. The better approach is to flush the data partly using flush() method rather than flushing whole data at a time. You can initially flush header, then navigation bar, then body content and finally footer so that the user need not wait for whole data and he sees the header data immediately and so on with navigation bar, body content and footer.

out.write(header);
out.flush(); // flush the header
out.write(navbar);
out.flush(); // flush the navigation bar
// write dynamic data here
out.flush(); // flush the dynamic data
out.write(footer);
out.flush(); // finally flush the footer