Re: io

From: Raymond DeCampo (rdecampo_at_hold-the-spam.twcny.rr.com)
Date: 10/29/03

  • Next message: harish: "silent installation of jvm"
    Date: Wed, 29 Oct 2003 01:30:02 GMT
    
    

    IS wrote:
    > Hi,
    >
    > I am new to java.io.* classes, and have a situation where I can't make a
    > copy of my binary files. Txt are being copied with no trouble but when it
    > comes to binaries i guess I am missing something since their structured is
    > changed and are not read by an application correctry (Word, ACDSee etc.).
    > At the moment, I have a JSP doing something like:
    >
    > response.setContentType("APPLICATION/OCTET-STREAM");
    > response.setHeader("Content-Disposition", "attachment; filename=\"" +
    > filename + "\"");
    > java.io.FileInputStream fileInputStream = new
    > java.io.FileInputStream(dbBean.getDataPath() + filename);
    > int i;
    > while ((i=fileInputStream.read()) != -1) {
    > out.write(i); }
    >
    > Please advise of where I am making a mistake or what other class and how
    > should I use.

    JSPs are not suited for returning binary data. There is a technical
    reason for this, the exact details escape me at the moment but the
    upshot is that a JSP automatically starts using the output stream for
    text. There was a tech tip from Sun that made the same mistake a while
    back.

    If you want to return binary data you should either use a servlet or
    have your JSP create the response under a web server and forward the
    request to it via the client.

    Ray


  • Next message: harish: "silent installation of jvm"

    Relevant Pages

    • Re: Dynamically include JSP file?
      ... >> page's text into your JSP before it's even compiled! ... Dang, now I realise my mistake. ... action as part of embedded Java code, ...
      (comp.lang.java.programmer)
    • Re: JSP File Viewer Problem: Error 404
      ... Since the last I tried was in ASP, I could be wrong with JSP, but I don't ... No one is listening until you make a mistake. ...
      (comp.lang.java.programmer)
    • Re: EJBs vs. Servlets ?!
      ... You are basically saying that you cannot serve binary data from ... Since JSPs practically are servlets, that means they do not have ... What I said was that JSP are designed to send character streams, ...
      (comp.lang.java.programmer)