Home Page becomes unresponsive after force downloading excel file from browser
Reply: 0

Page becomes unresponsive after force downloading excel file from browser

Ronaldo Killergod
1#
Ronaldo Killergod Published in 2018-02-04 18:35:34Z

I'm triggering an action exportToExcel() of a controller on click of a button where it reads List of data (listItems) from a web service and writes those data in excel format (poi jar) and makes the file as an attachment so that it prompts open/save from browser side. Problem is that after doing all this, the prompt comes and file downloads, but the page hangs and doesn't responds:

   void exportToExcel() {
        String file = params.exportFileName + ".xls"
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss") // add S if you need milliseconds
        String filename = file.split("\\.")[0] + df.format(new Date()) + "." + file.split("\\.")[1]
        ExportUtilityToXls util = new ExportUtilityToXls()
          HSSFWorkbook wb = util.writeExcelSheet(listItems)
        ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
        wb.write(outByteStream);
        byte[] outArray = outByteStream.toByteArray()
        response.setContentType("application/ms-excel")
        response.setContentLength(outArray.length)
        response.setHeader("Expires:", "0"); // eliminates browser caching
        response.setHeader("Content-disposition", "attachment;filename=\"${filename}\"")
        OutputStream outStream = response.getOutputStream()
        outStream.write(outArray)
        outStream.flush()
        outStream.close()
        }

Do I have to make changes in JS to redirect to the current page, but where? In the framework level JS this action is getting invoked by:

       window.location.replace("controllername/exportToExcel..")
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296174 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO