我要在成功下载Excel文件后显示警报消息。我的程序成功下载了文件,但没有显示警告消息。
我在下面添加了Java Servlet代码部分,该部分创建和下载excel文件。您能否建议我要发出警报消息该怎么做?
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=\"" + excelFileName + "\"");
.
.
. // excel creating code
.
.
// Write data in the excel
ServletOutputStream out = response.getOutputStream();
workbook.write(out);
// Close workbook
workbook.close();
// This below code is supposed to be executed to give alert message but it doesn't work
PrintStream pw = new PrintStream(out, true, "utf-8");
response.setContentType("text/html");
pw.println("<script type=\"text/javascript\">");
pw.println("alert('" + download_success_message + "');");
pw.println("history.back();");
// pw.println("location='jsp/Hus3report.jsp';");
pw.println("</script>");
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
} else {
PrintWriter pw = response.getWriter();
response.setContentType("text/html");
pw.println("<script type=\"text/javascript\">");
pw.println("alert('" + no_data_available + "');");
pw.println("history.back();");
// pw.println("location='jsp/Hus3report.jsp';");
pw.println("</script>");
}