×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

download files from server

download files from server

download files from server

(OP)
Hi, I'm trying to follow thread thread695-824677: "Save As" dialog box instructions, and it seems to work ok, except that the file created is 20 kB bigger than the original, and that files that are not plain text (like .doc or .zip) can't be opened.

Does anyone know what can cause this?

Thanks

RE: download files from server

(OP)
Sorry, it's not 20kB, it's 20 bytes that it adds, I think at the begining of the file.

Here is the code I've tried:

CODE

<netui-data:getData resultId="path" value="{pageFlow.filePath}" />
<netui-data:getData resultId="name" value="{pageFlow.fileName}" />
<%
    String path = (String)pageContext.getAttribute("path");
    String name = (String)pageContext.getAttribute("name");
    
    response.setContentType("application/octet-stream");
    response.setHeader("Content-disposition", "attachment;filename="+name);
    
    File myFile = new File(path);
    OutputStream o = response.getOutputStream();
    
    FileInputStream fis = new FileInputStream(myFile);
    int i = fis.available();
    System.out.println("fis.available: " + i);
    int iRead;
    int iLength = 0;
    while ((iRead=fis.read())!=-1)
    {
        o.write(iRead);
        iLength++;
    }
    System.out.println("iLength: " + iLength);
    fis.close();
    o.flush();
    o.close();
%>

When I execute this, both fis.available and iLength give the current size of the file, but the file created is 20 bytes bigger and is corrupt.

If I try this with a plain text file, I can see that it adds 10 blank lines at the begining of the file.

Does anyone know how to fix this?

Thanks.

RE: download files from server

(OP)
Well, I got it.

I was doing it in a JSP page, but it must be done from a servlet, because JSPs write more code than you want (each <%@ import inserts a blank line).

RE: download files from server

It seems that you use weblogic server

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close