response.setContentType(fileminitype);
response.setHeader("Location",filename);
response.setHeader("Cache-Control", "max-age=" + cacheTime);
//filename应该是编码后的(utf-8)
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.setContentLength(filelength);//下载文件的大小
OutputStream outputStream = response.getOutputStream();
InputStream inputStream = new FileInputStream(filepath);
byte[] buffer = new byte[1024];
int i = -1;
while ((i = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, i);
}
outputStream.flush();
outputStream.close();
inputStream.close();
outputStream = null;
jsp下载
最新推荐文章于 2022-07-25 10:50:44 发布