I went through the answers/discussion about the same/similar issue and find out that I should be using "response" method either to download file or to get HTML page at one time. In my case after the successful download of the file, I want to show success alert message. And when I use "response" method to download file and to print success alert message I always get: getOutputStream() has already been called for this response exception.
What is the correct way to solve this problem?
Below is the section of my code:
// Write data in the excel
ServletOutputStream out = response.getOutputStream(); => It successfully creates excel file
workbook.write(out);
// Close output stream and workbook
workbook.close();
out.flush();
out.close();
PrintWriter pw = response.getWriter(); => My problem is here!!
response.setContentType("text/html");
pw.println("<script type=\"text/javascript\">");
pw.println("alert('" + message + "');");
pw.println("history.back();");
pw.println("</script>");