Dargaard
04-05-2006, 10:17 AM
Hello!
I have some troubles getting "filename" from IBM WebSphere 5.1 server.
I'm using Internet Explorer 6.0 as browser,
and this code doesn't seem to work properly.
Although when I'm looking to application log, and the
size is correct, and index i is (filesize+1) as should be,
somehow only the first 712716 of 714933 bytes ar written
in file.
No error is logged with the catch exception...
I wonder why my application doesn't download whole file from
server. (The last bytes of downloaded file is "Error 500" which
is not any message i wrote in code or a part of the file from server.
Any indication of how to solve this problem are apreciated.
// [ ... ]
try {
File f = new File(filename);
response.setHeader("Content-length", ""+(int)f.length());
response.setHeader("Content-Disposition", "attachment; filename=\""
+ filename + "\"");
response.setContentType("application/octet-stream");
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Expires", "Thu, 01 Dec 1970 16:00:00 GMT");
int fsize = (int)f.length();
//response.setContentLength( fsize );
log.error("filename on server = "+filename+" dim = "+fsize);
InputStream in = new FileInputStream(f);
ServletOutputStream outs = response.getOutputStream();
int bit = 256;
int i = 0;
while ((bit) >= 0) {
bit = in.read();
outs.write(bit);
i++;
}
log.error("final index of file is "+i);
outs.flush();
outs.close();
in.close();
} catch (Exception e) {
log.error(e);
}
// [ ... ]
I have some troubles getting "filename" from IBM WebSphere 5.1 server.
I'm using Internet Explorer 6.0 as browser,
and this code doesn't seem to work properly.
Although when I'm looking to application log, and the
size is correct, and index i is (filesize+1) as should be,
somehow only the first 712716 of 714933 bytes ar written
in file.
No error is logged with the catch exception...
I wonder why my application doesn't download whole file from
server. (The last bytes of downloaded file is "Error 500" which
is not any message i wrote in code or a part of the file from server.
Any indication of how to solve this problem are apreciated.
// [ ... ]
try {
File f = new File(filename);
response.setHeader("Content-length", ""+(int)f.length());
response.setHeader("Content-Disposition", "attachment; filename=\""
+ filename + "\"");
response.setContentType("application/octet-stream");
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Expires", "Thu, 01 Dec 1970 16:00:00 GMT");
int fsize = (int)f.length();
//response.setContentLength( fsize );
log.error("filename on server = "+filename+" dim = "+fsize);
InputStream in = new FileInputStream(f);
ServletOutputStream outs = response.getOutputStream();
int bit = 256;
int i = 0;
while ((bit) >= 0) {
bit = in.read();
outs.write(bit);
i++;
}
log.error("final index of file is "+i);
outs.flush();
outs.close();
in.close();
} catch (Exception e) {
log.error(e);
}
// [ ... ]