• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing multiple images to Browser

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am reading a file and then try to pass it as an output of a Servlet response as follows:

ServletOutputStream out = response.getOutputStream();
File file = new File("somelaocation\\image1.jpeg");
response.setContentType("image/jpeg");
response.setHeader("Content-Disposition","inline");

FileInputStream in = new FileInputStream(file);
byte[] bytes = new byte[10000];
// Read in file and at the same time write the stream to the resposne.
while (true) {
int count = in.read(bytes);
if (count == -1)
break;
out.write(bytes, 0, count);
}

Now I have to pass many images to the output. So how is that accomplished?

I just tried a very RAW way of doing it (i.e by reading another file and passing it out again ) but it just doesnt work:

file = new File("someImage/image2.jpeg");
in = new FileInputStream(file);
byte[] bytes2 = new byte[10000];
while (true) {
count = in.read(bytes2);
if (count== -1)
break;
out.write(bytes2, 0, count);

}

Please advice. It only passes the first image.BOTH the images do not come SIMULTANEOUSLY! Matter is crucial.

Thanks in advance,
MD
[ April 08, 2005: Message edited by: milan doshi ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at SimpleStream at http://simple.souther.us.
The browser will assemble the page out of multiple requests.
The first is for the HTML. It then reads the HTML and makes a new request for each image.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please advice. It only passes the first image.BOTH the images do not come SIMULTANEOUSLY! Matter is crucial.


Stop and think for a moment - what does an HTML page that contains multiple images look like?
Right - each image is obtained by a separate request in a separate IMG tag. The browser may be assembling the final page out of dozens of separate requests - it never gets multiple resources in a single request.
When in doubt about how to get a servlet to build a page design, create a mock-up in plain HTML first.
Bill
 
milan doshi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,

..The browser may be assembling the final page out of dozens of separate requests - it never gets multiple resources in a single request.



So what do I do now? How do I pass many images?Sorry..for sounding dumb...(but thats what I am)...

Thanks,
MD
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start by passing text, HTML to be exact.
Did you look at the example link I gave you?
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
i think ur hardcoding works well..
better u may try above option told by ther professionals..

and also try this option .

out.flush(); method after writing output streams..

cheers
vasu
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic