• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Downloaded file contains garbage value

 
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to download a .doc file from my DB2 database.

The uploading portion , works fine.

But , when I am trying to download, the downloaded file contains garbage value.




and here 's the main culprit :


download2.jsp:



Here's my table structure :




Can you tell me where's the problem ?

Thanks in advance...
 
Shounak Kundu
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, the problem has been resolved..

I was damn foolish to rs.getString the BINARYFILE. Later , I changed to rs.getBytes , and everything worked fine.

But, now I have one problem:

How can I print the content of the .doc file on the browser ?

I mean , what MIME type I have to use ?

I have tried using "application/msword" , but it is prompting to download rather than printing the content .

the "text/plain" and "text/html" are printing unwanted ascii characters and that looks horrible

Can you please help me ?






 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's move this to our JSP forum.

Shounak Kundu wrote:


Please don't use this String constructor, ever. Just use And Content should of course start with a lower case c.


You're writing to the response using both the Writer ("out") and the ServletOutputStream ("outs"). That's not going to work. You should either write to the Writer, or to the ServletOutputStream. Not to both. Warning: any enters in the JSP file outside of the JSP tags are still sent to the Writer. This includes enters between JSP directives like imports etc. That's why JSP files are not that great for handling binary files.
 
Rob Spoor
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shounak Kundu[b wrote:How can I print the content of the .doc file on the browser ?[/b]

I mean , what MIME type I have to use ?

I have tried using "application/msword" , but it is prompting to download rather than printing the content .

the "text/plain" and "text/html" are printing unwanted ascii characters and that looks horrible


When you use text/plain or text/html the binary contents are printed as if they were text. That's definitely not going to work.
In fact, there is nothing at all you can do about this. You already have the right MIME type. The problem is in the browser. Browsers can display text, HTML, XML and most images. For most other content they need a plugin. PDF and Flash are well-known plugins for browsers. So you'll need to install a plugin that will display the Word file for you. Unfortunately, I have never heard of any such plugin.
 
Ranch Hand
Posts: 88
Spring Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well rob that is not entirely correct, probably you can look in to apache tika.
Its a two min api to learn.

So, you can pass stream of bytes and convert you word document to html on the fly.
Only drawback is, it is little CPU intensive. Other libraries are mostly paid.
 
reply
    Bookmark Topic Watch Topic
  • New Topic