tags:

views:

239

answers:

1

I want to send multiple .png images as an single image through servlet response.getOutputStream().write(encoder.pngEncode()); But i can send only one image at a time,but i need to send multiple images through response object using java. If anyone knows please give me your inputs.

   // Create a set of charts
   JFreeChart chart1=null;

   BufferedImage buf[] = new BufferedImage[5]; 
   PngEncoder encoder[] = new PngEncoder[5]; 
   for (int i=0; i<5; i++ ) 
   {            
       buf[i] = chart[i].createBufferedImage(400, 350, null); 
       encoder[i] = new PngEncoder( buf[i], false, 0, 9 ); 
       System.out.println("i= "+i); 
       resp.getOutputStream().write( encoder[i].pngEncode() );           
   }
A: 

Why do you need to send multiple images through a single response?

While possible by using a multi-part MIME response, this is highly unusual and rarely implemented as the client needs to know how to interpret it. If your client is just some an arbitrary web browser, this approach won't work. If your client is your own applet/software, then maybe.

Another option might be to send a single image that is built up from other images, but that would depend very much on your use case.

Stu Thompson
currently i am doing monitor screen for my application,in this i need to display multiple jfree charts in a single jsp using servlet response.right now i am displaying one chart at a time ,but i am having five charts three timeserious chart and two bar chart.but in pie chart it is possible becoz predefined api is there ,but in rest of the charts how do i send in a single image ,please explain with code sample.
*"plzsendtehcodes"*? Haha. I don't have any. You are going to have to do some research and experimentation. I repeat: this is unusual, and your client must support it. You have not defined your client, so I cannot tell if this idea even has a chance of working. Are you sending this to a browser? And what is wrong with separate requests?
Stu Thompson
ya,browser only,in jsp page onclick of submit based on the input param i need to display all the jfree chart results,right now i am using dropdown list for each and every chart need to display,so based on the chart number i am displaying particular chart from the JFreeChart api in my servlet class,i have done 5 type of charts and i am having .png byte array also,but i can send one by one at a time ,but my requirement is onclick of submit i need to display all the charts in a single page,i am not using struts,it is simple jsp and servlet.
OK. Either *A)* have HTML show 5 separate images (and 5 requests). Or *B)* combine the 5 images into a single image--one on top each other.
Stu Thompson