• 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

Combining Binary and Character data

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a servlet which gets an image from an remote servlet through an URL request and stores that image in the form of an byte array. The servlet writes this image byte array directly to the response stream which displays the image properly in the browser.
Now I want to send some text with the image as a response, I tried to append the text to the same byte array in which the image is stored but in this case neither image nor text is getting printed. Is there any way by which I can combine my image and text together in the form of byte array and write it into the response stream.

If any body has any idea or reference links please send me

Thanks & Regards
-Sandeep
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The client sends two requests, one for the page and then one for the image. You can't send text when the client is expecting an image, it just doesn't work that way.
 
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
If you want an example app that streams images to a browser, I have one on my site.
Simple Servlet Examples
Look for SimpleStream.

As David mentioned, the images and HTML are not sent in the same request.
The HTML is loaded first and then for each <img..> tag, in the page, a new request is made.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Sandeep K.M",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
sansandy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No the client here wont be sending two request like one for image and one for text instead it will be a single request but my servlet should hit another two servlets.

Suppose Servlet1 (which is my servlet) makes two HttpURL connections to different servlets in which one returns an image and one returns a text now I have to combine both image and text into a single byte array and have to send back to client. If you know any tricks and strategies to implement it please suggest.


I tried to attach an image which displays the scenario but i was not able to do it or as i am new to this forum i dont know how to paste an image
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Sandeep K.M/sansandy", you have been warned on multiple occasions in this and your other post regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Again, your display name must be a first name and a last name. First names only are not allowed, nor are initials for your last name.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
[ May 24, 2006: Message edited by: Bear Bibeault ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic