This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ho to display image getting from byte array in JSP ?

 
Thomas Houseman
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I receive an image as byte array (byte[]) from a servlet to a jsp page and i'm trying
to display this image in the jsp.
How should I do that ? How should I transfer this byte[] to image which I can see in the jsp page ?

Thanks !
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Handling binary data should be left to the servlet; JSPs are meant for textual output (like HTML).

The two ways I see are a) store the byte[] as a file with a known name, and then use that filename in the the img tag of a JSP page, or b) keep the data in memory (maybe as a session or application attribute), and have a servlet stream it to the client (with the servlet's URL in the image tag's "src" attribute).
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Ulf has pointed out, you've put the cart before the horse.

Remember that all a JSP is is a way to create an HTML page to send the browser. And when putting an image into an HTML page do you embed binary data? Of course not. You create an image tag that references a resource (usually an image file) that serves the binary data.

Same thing here. You shouldn't be fetching the image data at all in the request that generates the JSP. Rather, create an image tag on the JSP that references a different servlet that serves up the binary data when asked for it.
 
Thomas Houseman
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i will try that.
thanks !
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic