• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing large data to HTTPResponse object  RSS feed

 
Sudipta Banerjee
Greenhorn
Posts: 4
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want tot write a large amount of data(say 6/7 MB) to the response object from a struts2 action class or jsp like this:

#1.
L1. PrintWriter out = response.getWriter();
L2. String data = getEntireRecord(); // large data
L3. out.println(data);

but it takes significant time to print, around 20 seconds, and I want to minimize it.

Initially I also tried like this(write small data while iterating):

#2.
L10. for(....){
// iterating through a list of records
L11. data = getRecord(); // collect each record
L12. out.println(data); //and write it to response
}
** this is more time consuming
**I have no option to use socket**

may be I'm missing some basic approach. Give some idea to deal with this.

[** Don't know if there is any way, so that while writing each small piece of data to response(as above line L12),
forward that data to client(browser)while still iterating, all this to happen in a single action call. is that possible to
partially return the data to browser while the action is executing.]

May be my question sounds bogus, but I need to solve this.

Thanks in advance.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. is that possible to
partially return the data to browser while the action is executing.


The response output stream is buffered - when the buffer is full, it is written to the connection. This happens no matter how you choose to call a print routinge. Howver note that using:



creates an unnecessary very large String.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!