Я хочу показать предупреждение после успешной загрузки файла Excel. Моя программа успешно загружает файл, но не показывает предупреждающее сообщение.
Я добавил раздел кода Java-сервлета ниже, который создает и загружает файл 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>");
}