This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to make sense of my binary data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "How to make sense of my binary data" Watch "How to make sense of my binary data" New topic

How to make sense of my binary data

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
Ok, so I have managed to upload an image... It was written to a BinaryOutputStream and then written to a String object (following the struts sample). I think I have done this right only that, doing ${picture} outputs a set of ascii code such as

!1AQa?"Rq?��2B����#3CS?$4br�?��� ?��?��?� #���^?C�???@��?`�Cd��L �c�?� ����?�?��??�?�t&?~�?�?0 ct�"=�(T?B?@!@B??!!@B??!!@B??!!@B??!!@B??!!@B??!!@B?!PH�???A$� ?�e�H�?�@D��} ~�?�B?���I�G�?"|��G��G;$I��H�����I�?;n??L�|��?D?O��F�#?;?g�o�G�?PF�T) ?N�7<�Qpo?Dq??�vI�jG���N{&2w�h��.��*J?�?�o�i{? ?�1�`c���h��1�0?��?�??@l���Jc; o�a@G??I�T?:&?�B" B? ! ?B?? !BB?? !BB?? !BB?? !BB?? !BB?? !BB?? ! B ! ! BX??(QwH��4�??� %B??�R>??�I�*G��Q=w@.�'d��:y$R?�����I��D� $g�H�8?3��H��#��K�#�PA�?%D��G�#?�?(?��tQ;n�(?�Bx��h�"���L���H[��??�#

and what I really want is to use the uploaded file(binary data) into an image tag in one of my jsp's... How am I suppose to do this? Thanks!
[ May 31, 2006: Message edited by: Bear Bibeault ]

SCJP 1.5 -
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
You'll need to store the binary data from the image somewhere (A file on the file system or cached in memory) and create an html image tag to something that will serve the image up. If you save it as a file , it can simply be the URL to the image. If you save it in memory, you'll need to have a servlet output the contents.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
Hi, thanks for your reply...

If you save it in memory, you'll need to have a servlet output the contents.

This is exactly what I need to do. I saw some samples on the internet but doesn't actually understand how they work... One thing for example, this code found at this page...

I understand how the other lines work... But I don't know how the image is sent back with the response... Here's another code which confuses me...

thank you...
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
You need to write a simple servlet or JSP which sets content type to something like image/png and write your saved in memory or file image to servlet output stream. Access your image servlet from page using something like: <img src="/mycontext/myimageservlet?imageid=xxx">
You can look in example of a contact application in my signature. It allows to upload image (photo) and display it on page after.

Tough in space?, <a href="" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="" target="_blank" rel="nofollow">Check it here.</a><br /><a href="" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: How to make sense of my binary data
It's not a secret anymore!