my dog learned polymorphism*
The moose likes Servlets and the fly likes Combining Binary and Character data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Combining Binary and Character data " Watch "Combining Binary and Character data " New topic
Author

Combining Binary and Character data

sansandy
Greenhorn

Joined: May 24, 2006
Posts: 5
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
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60773
    
  65

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sansandy
Greenhorn

Joined: May 24, 2006
Posts: 5
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60773
    
  65

"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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Combining Binary and Character data
 
Similar Threads
How to Upload Image in to Server?
send audio and text via one http connection?
Fetching image from database
Showing PDF in a new window
UTF8 java + arabic