You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ariel <is...@gmail.com> on 2008/10/13 20:31:46 UTC

How to allow to download several files in a zip in Internet Explorer

Hi Everybody:
I 'm using struts 1.2 version, in my web application I have a chart where
the user can add several files that are located in the server, then in a
hiperlink the user decide to download the several files in a zip file. I
implemented this functionalities, in Mozilla Firefox works perfectly but
with Internet Explorer doesn't work.
Please could you help to find how to do it correctly to make it works in
both browsers ???
Here I post a piece of my code:
<Code>
             ServletContext      context  =
getServlet().getServletContext();
             String              mimetype =
context.getMimeType(filename);
             resp.setContentType( (mimetype != null) ? mimetype
:"multipart/mixed" );
             resp.setHeader( "Content-Disposition", "attachement;
filename=\"chart.zip\"" );
             ZipOutputStream zos = new
ZipOutputStream(resp.getOutputStream());
             ChartStructure chart = (ChartStructure)
req.getSession().getAttribute("chart");
            byte[] buf = new byte[1024];
            int len;
             for (Iterator<Files> iterator = chart.iterator();
iterator.hasNext();){
                 Files elem = iterator.next();
                 ZipEntry zipEntry = new
ZipEntry(elem.getPhisicalFileName());
                 String filepath = elem.getDownloadLink();
                FileInputStream fin = new FileInputStream(path);
                BufferedInputStream in = new BufferedInputStream(fin);
                zos.putNextEntry(zipEntry);
                while ((len = in.read(buf)) >= 0) {
                   zos.write(buf, 0, len);
                }
                in.close();
                zos.closeEntry();
            }
             zos.close();
</Code>

I hope you can help me.
Greetings
Ariel

Re: How to allow to download several files in a zip in Internet Explorer

Posted by Lance Java <la...@googlemail.com>.
Try zos.flush() instead of close()
It is not your responsibility to close the servlet output stream, it is the
container's.

2008/10/13 Ariel <is...@gmail.com>

> Hi Everybody:
> I 'm using struts 1.2 version, in my web application I have a chart where
> the user can add several files that are located in the server, then in a
> hiperlink the user decide to download the several files in a zip file. I
> implemented this functionalities, in Mozilla Firefox works perfectly but
> with Internet Explorer doesn't work.
> Please could you help to find how to do it correctly to make it works in
> both browsers ???
> Here I post a piece of my code:
> <Code>
>             ServletContext      context  =
> getServlet().getServletContext();
>             String              mimetype =
> context.getMimeType(filename);
>             resp.setContentType( (mimetype != null) ? mimetype
> :"multipart/mixed" );
>             resp.setHeader( "Content-Disposition", "attachement;
> filename=\"chart.zip\"" );
>             ZipOutputStream zos = new
> ZipOutputStream(resp.getOutputStream());
>             ChartStructure chart = (ChartStructure)
> req.getSession().getAttribute("chart");
>            byte[] buf = new byte[1024];
>            int len;
>             for (Iterator<Files> iterator = chart.iterator();
> iterator.hasNext();){
>                 Files elem = iterator.next();
>                 ZipEntry zipEntry = new
> ZipEntry(elem.getPhisicalFileName());
>                 String filepath = elem.getDownloadLink();
>                FileInputStream fin = new FileInputStream(path);
>                BufferedInputStream in = new BufferedInputStream(fin);
>                zos.putNextEntry(zipEntry);
>                while ((len = in.read(buf)) >= 0) {
>                   zos.write(buf, 0, len);
>                }
>                in.close();
>                zos.closeEntry();
>            }
>             zos.close();
> </Code>
>
> I hope you can help me.
> Greetings
> Ariel
>