当客户端浏览器请求下载zip文件并且用户取消下载之间的时间时,我想在服务器上收到通知,我是否知道用户取消下载zip文件时的事件。
This 是我所引用的代码参考。
问题在于,当用户关闭浏览器时,下面的代码行仍在服务器上执行。所以在这里我想知道用户下载何时中断。
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String filename = "home.jsp";
String filepath = "e:\\";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
FileInputStream fileInputStream = new FileInputStream(filepath + filename);
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
out.close();
}
谢谢