On Wednesday, October 20, 2010 5:49:12 AM UTC+2, mike b wrote:
>
> I have read all the other posts about downloading Excel files and how 
> to do it w/ an IFRAME, with RequestBuilder, and Window.open(). 
> However, none of them actually work.  Luckily, I have a working 
> servlet which executes and returns successfully with javascript. 
> However, we'd like to do it all in GWT.  The error message from IE is 
> below.  The Window.open() DOES work with FF, but not with IE. 
> Unfortunately, we must deploy to IE, no options there. 
>
> Situation: 
> GWT 2.0.4  mvp4g 1.2.0 
> Need to download a file to open in Excel.  At this point, its actually 
> a text file, but the MIME type is setup for Excel. 
>
> The servlet has been tested w/ straight java script using 
> "document.body.appendChild(iframe);".  This works like a champ in IE 
> and FF. 
>
> However, when I do "Window.open(url, "_self",null);" in GWT, IE can't 
> download the file.  It throws an error saying... 
>
> " 
> Internet Exploroer cannot download MyFile from localhost 
>
> IE was not able to open this Internet site.  The requests site is 
> either unavailable or cannot be found.  Please try again later. 
> " 
>
> In GWT, I have also tried just using a Frame, adding it to a Panel, 
> and then calling myFrame.setUrl("myUrl"); 
>
> This also successfully gets to the servlet, but fails w/ the above 
> error message while trying to "open" the file. 
>
> It seems as if GWT is telling the browser to cancel the download when 
> it pops up. 
>
> Any suggestions?  Any guesses? 
>
> Thanks, 
> mikeb




Hi, I am following the steps described by Jim Douglas. I want to read Zip 
file at server side and allow client to download at button click event. 

*SERVER SIDE Code*: 

protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, 
IOException {
        super.doGet(request, response);
        
        // load settings
        dbSettings();

        String filename = request.getParameter("filename");

        if (filename == null) {
            response.sendError(SC_BAD_REQUEST, "Missing file Name");
            return;
        }

        // Load zip file with filename from Backup Directory
        File zipFile = new File(fileBackupPath + File.separator + filename 
+ ".zip");
                                
        File file = new File(zipFile.toString());
             
        long length = file.length();
        FileInputStream fis = new FileInputStream(file);
        response.addHeader("Content-Disposition","attachment; filename=\"" 
+ filename + "\"");        
        response.setContentType("application/zip");
        
        if (length > 0 && length <= Integer.MAX_VALUE);
            response.setContentLength((int)length);
            
        ServletOutputStream out = response.getOutputStream();
        response.setBufferSize(32768);
        
        int bufSize = response.getBufferSize();
        byte[] buffer = new byte[bufSize];
        
        BufferedInputStream bis = new BufferedInputStream(fis,bufSize);
        
        int bytes;
        while ((bytes = bis.read(buffer, 0, bufSize)) >= 0)
            out.write(buffer, 0, bytes);
        
        
        bis.close();      
        fis.close();
        
        out.flush();
        out.close();
    

*CLIENT SIDE:*

String url = GWT.getModuleBaseURL() + "FileUploadDownloadServlet?filename=" 
+ filename;
Window.open(url, "_blank", "status=0,toolbar=0,menubar=0,location=0");


*I get this ERROR: *

HTTP Status 500 - Cannot change buffer size after data has been written


Please guide and help me out. Thanks in anticipation

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to