0

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>");
sä-röze
  • 13
  • 1
  • 7

1 Answers1

0

You are trying to return two objects in the response of the same HTTP request. This is not how HTTP works. No browser will support that.

AFAIK, there's no way to detect "download complete" event in javascript.

Mateusz Stefek
  • 3,478
  • 2
  • 23
  • 28