• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hww to get a web browser display a tiff image generated dynamically by JSP

 
Ketan Joshi
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All

I am product called Documentum which is an enterprise content management solution

It has its own classes Documentum foundation classes(DFC) which can be used for inserting and extracting any document into a repository.The document may be a web page, Word document, pdf or an image


I have a jsp page and I have imported the DFC specific packages

Using these classes a tiff image from the repository is being picked up and

and being displayed to the user

However the content is all garbled
I have trid using response.setContentType("image/tiff");
I also downloaded a plugin for web browser which enables the browser to show tiff images

Still the image is all garbled

To give you a better idea, here is the portion of the scriplet that gets the image from the documentum server


ByteArrayInputStream b=s.getContent();
/*getContent method returns the contents of any document that you specify

the response is available as Byte ArrayInputStrem */

int n=b.available();

for(int i=0;i<n;i++)

out.print((char)b.read());


This code successfully displays all documents which are of type html

Please suggest something

Thanks and Regards
Ketan
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello "ksj"-

On your way in you may have missed that JavaRanch has a policy on display names, and yours does not comply with it - please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, thank you for fixing your name.


The 'out' writer object in JSP is a text writer.
If you want to stream binary data to a browser, you would want to use response.getOutputStream
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#getOutputStream()

If you want some sample code, I have a demo app that streams images from disk.
http://simple.souther.us
Look for SimpleStream
[ February 28, 2006: Message edited by: Ben Souther ]
 
Ketan Joshi
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Thanks for the prompt reply

I had already realised that for an image to be displayed on the web brower , we need to use the response.getOutputStream()

However the main issue was that in my code , I was using out.println((char)b.read())

As a result the ascii values returned from the read method were converted to character causing the output to be garbled.

This casting is required only when we print characters

And I realised this after looking at the code sample posted by you

Thanks a lot.My issue is resolved

Thanks once again and Best Regards
Ketan Joshi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!