Meaningless Drivel is fun!*
The moose likes JSP and the fly likes Display image from the binary data in form of String in a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Display image from the binary data in form of String in a JSP" Watch "Display image from the binary data in form of String in a JSP" New topic
Author

Display image from the binary data in form of String in a JSP

binu narayanan
Ranch Hand

Joined: Jul 24, 2009
Posts: 56
Hi Everybody,

I have a String with image in Base 64 encoded binary format. I would like to display the same in a JSP. Kindly guide me how to achieve this.

The string with data say

[ridiculously long Base64 string removed]

Kindly help me in achieving this
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
1. absolutely nothing was served by posting that whole monster string.
2. There is no reliable way to serve binary data from JSP, JSP assumes character data
3. each image on a HTML web page takes a separate request in an IMG tag
4. in a JSP you must create a URL for an IMG tag that points to a servlet which can serve the binary data with correct headers for type and content-length

Bill
binu narayanan
Ranch Hand

Joined: Jul 24, 2009
Posts: 56
Hi Bill,

I just came across this piece of code for achieving what i had asked earlier

The value of the strImage is the monstrous value of the image in binary format.



Can you give an idea of how the servlet can help me get the image on the fly in a jsp

Thank you

Binu
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

http://stackoverflow.com/questions/1154254/help-getting-image-from-servlet-to-jsp-page
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JSP/Q_21986929.html


Regards, Rene Larsen
Dropbox Invite
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
This Wikipedia article discusses the use of "data" in IMG tag URLs - apparently it is not universally supported so you risk failure for some users.

Bill
binu narayanan
Ranch Hand

Joined: Jul 24, 2009
Posts: 56
Hi Bill,

Thanks for the info.

Could like to get a little bit of help in creating a servlet to render the base 64 encoded binary string.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Display image from the binary data in form of String in a JSP