*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
Author

How to make sense of my binary data

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
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
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Carl Trusiak
Sheriff

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: 746
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="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make sense of my binary data
 
Similar Threads
Captcha problem
Save file without unwanted extensions
Tomcat madness!
Pop up calendar Problem
extracting image binary data from file