The fundamental problem here is that a .doc file is a *byte* stream, not
a character-oriented text document.  You are seeing the effects of
character set translation and possibly truncation and probably some
problems due to null characters (though Java should not have any prob.
with this).

You need to make the junk.getDoc() return a byte[] array, then use
out.write(bytes) to output that back to the browser.  E.g.,

    public byte[] getDoc() throws IOException {
        File docFile = new File("myWord.doc");
        InputStream in = new BufferedInputStream(
                new FileInputStream(docFile) );
        byte[] buf = new byte[docFile.length()];
        in.read(buf);  // should verify #bytes read here.
        return buf;
    }

Next issue is that .jsp pages are designed for *text* output, not binary
output -- you should put your code in a Servlet.

                        -=- D. J.

Eric Butler wrote:
> The junk.getDoc() return a string that's just the reading of a file
> input stream.  The strange thing this is that if I create a file in the
> jsp and the write the results of getdoc to the file, the correct file is
> saved to disk.  Only when the result is spewed through http does it get
> hosed.
>
> I have also tried changing the getDoc to return an array of bytes and
> trying to morph that back into a valid file but I failed.
>
> Here's the code.  I've tried multiple permutations of commenting out
> and/or changing the first two lines.
>
> <%
>     response.setHeader("Content-Disposition", "inline;
> filename=word.doc");
>     response.setHeader( "Content-type", "binary/octect-stream");
>     String myWordDoc = junk.getDoc();
>     out.print ( myWordDoc );
> %>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to