81,092
社区成员
发帖
与我相关
我的任务
分享
OutputStream out = response.getOutputStream();
fileinputstream = new FileInputStream(file);
long l = file.length();
int k = 0;
byte abyte0[] = new byte[65000];
response.setContentType("application/x-msdownload");
response.setContentLength((int) l);
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
while ((long) k < l) {
int j;
j = fileinputstream.read(abyte0, 0, 65000);
k += j;
out.write(abyte0, 0, j);
}
out.flush();
out.close();
if (map != null) {
// 获取当前人员ID、姓名
String webID= (String) map.get("webID");
String userID= (String) map.get("userID");
String userName= (String) map.get("userName");
String file_id= (String) map.get("file_id");
int doType=1;
fileService.updateFileInfoAndLog(file_id, userID, userName, doType,webID);
}
这是输出流那边的代码 我在最后一行fileService.updateFileInfoAndLog 加了断点做测试 页面上只要点了那个链接 不管你有没有点下载或者是取消 代码直接走到最后一行
我想要的是 当你点了下载之后 再执行那段代码[/quote]
我觉得是你只要下载页面弹出的时候,这个文件就已经写到了response中了,所以out.close()肯定执行了,并且fileService.updateFileInfoAndLog也肯定执行了,你所说的点击下载或者取消是浏览器的行为,和上面代码没有关系。
不知道这样对不对,请大家指正。
OutputStream out = response.getOutputStream();
fileinputstream = new FileInputStream(file);
long l = file.length();
int k = 0;
byte abyte0[] = new byte[65000];
response.setContentType("application/x-msdownload");
response.setContentLength((int) l);
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
while ((long) k < l) {
int j;
j = fileinputstream.read(abyte0, 0, 65000);
k += j;
out.write(abyte0, 0, j);
}
out.flush();
out.close();
if (map != null) {
// 获取当前人员ID、姓名
String webID= (String) map.get("webID");
String userID= (String) map.get("userID");
String userName= (String) map.get("userName");
String file_id= (String) map.get("file_id");
int doType=1;
fileService.updateFileInfoAndLog(file_id, userID, userName, doType,webID);
}
这是输出流那边的代码 我在最后一行fileService.updateFileInfoAndLog 加了断点做测试 页面上只要点了那个链接 不管你有没有点下载或者是取消 代码直接走到最后一行
我想要的是 当你点了下载之后 再执行那段代码
OutputStream out = response.getOutputStream();
fileinputstream = new FileInputStream(file);
long l = file.length();
int k = 0;
byte abyte0[] = new byte[65000];
response.setContentType("application/x-msdownload");
response.setContentLength((int) l);
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
while ((long) k < l) {
int j;
j = fileinputstream.read(abyte0, 0, 65000);
k += j;
out.write(abyte0, 0, j);
}
out.flush();
out.close();
if (map != null) {
// 获取当前人员ID、姓名
String webID= (String) map.get("webID");
String userID= (String) map.get("userID");
String userName= (String) map.get("userName");
String file_id= (String) map.get("file_id");
int doType=1;
fileService.updateFileInfoAndLog(file_id, userID, userName, doType,webID);
}
这是输出流那边的代码 我在最后一行fileService.updateFileInfoAndLog 加了断点做测试 页面上只要点了那个链接 不管你有没有点下载或者是取消 代码直接走到最后一行
我想要的是 当你点了下载之后 再执行那段代码[/quote]
因为你的流写完了 你可以在while中打断点