1

I'm looking for a good example which explains how to download files from the server side of a web app created with Struts 1.1 and JSP;

I tried to follow some tips like this:

Best download file with struts 1.1 method

https://www.mkyong.com/struts/struts-download-file-from-website-example/

I can create the file, put it in the HttpServletResponse and correctly open it through the message that appears from the browser (I have to use IE11, unfortunately), but after opening (or closing) the .xls file, the page remains locked while loading.

I have found that the page remains blocked as soon as the message opening the excel file appears.

This is part of my code in the Action:

    OutputStream out = response.getOutputStream();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=ExcelSheet.xls");
    FileInputStream in = new FileInputStream("ExcelSheet.xls");
    byte[] buffer = new byte[4096];
    int length;
    while ((length = in.read(buffer)) > 0){
        out.write(buffer, 0, length);
    }
    in.close();
    out.flush();

    //others insignificant lines of code

    return null;

and this is the message that appears on the browser:

browserMessage

As soon as this message appears, the page keeps loading infinitely.

How can I stop the infinitely loading?

  • Return to the page you left? Hit the "back" button; the file download *is* the page you left. You need to set the content disposition, though, e.g., https://www.mkyong.com/struts/struts-download-file-from-website-example/. – Dave Newton Jul 16 '18 at 23:59
  • Ok, I'll fix the question, I already set the content disposition but despite this, it does not work! I need to open the excel file (and I do it correctly) without keep loading infinitely on the download page – ElliotAndersson Jul 17 '18 at 10:27

0 Answers0