title: Sending ZIP file from servlet to client not working
body: <p>I am trying to send a zip file from a Java servlet to a JavaScript client. I first generate the zip archive on the disk, and then I try to send it to the client. The zip generation works fine. However, I have a problem with sending it to the client.</p>
  
  <p>The code related to sending the file to the client (inside <code>doPost</code>) is the following:</p>
  
  <pre><code>  String path = getServletContext().getRealPath("/") + "generatedApps/";     
    String fileName = appName + "Archive.zip";
    File f = new File(path + fileName);       
  
    response.setContentType("application/zip");     
    response.setContentLength((int)f.length());  
    response.addHeader("Content-Encoding", "gzip"); 
    response.addHeader("Content-Disposition","attachment;filename=\"" + fileName + "\"");    
    byte[] arBytes = new byte[(int)f.length()];     
    FileInputStream is = new FileInputStream(f);     
    is.read(arBytes);     
    ServletOutputStream op = response.getOutputStream();     
    op.write(arBytes);     
    op.flush();    
  </code></pre>
  
  <p>This is the Ajax request from the client:</p>
  
  <pre><code>new Ajax.Request( source, {
    asynchronous: false,
    method: 'post',
    parameters: {content: RWSMLFile},
    onSuccess: function(transport){                   
      console.log(transport);
    }.bind(this),
    onFailure: (function ( transport ) {
      ORYX.Log.error( "Sending RWSML file failed! Info: " + transport );
    }).bind( this )
  } );
  </code></pre>
  
  <p>In the browser console I get the following error:</p>
  
  <pre><code>POST http://localhost:8080/oryx/generategeddyjscode  prototype-1.5.1.js:1044
    Ajax.Request.Object.extend.request prototype-1.5.1.js:1044
    Ajax.Request.Object.extend.initialize prototype-1.5.1.js:1006
    (anonymous function) prototype-1.5.1.js:37
    ORYX.Plugins.RWSMLSupport.ORYX.Plugins.AbstractPlugin.extend.generateGeddyJsCode rwsmlSupport.js:47
    (anonymous function) prototype-1.5.1.js:105
    a.each.j.functionality default.js:2828
    Ext.Button.Ext.extend.onClick ext-all.js:87
    V ext-all.js:13
    O
  </code></pre>
  
  <p>If I go to the <code>Source</code> tab, then I get <code>Failed to load resource</code> after the last line of the following code snippet:</p>
  
  <pre><code>  if (this.options.onCreate) this.options.onCreate(this.transport);
    Ajax.Responders.dispatch('onCreate', this, this.transport);
  
    this.transport.open(this.method.toUpperCase(), this.url,
      this.options.asynchronous);
  
    if (this.options.asynchronous)
      setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);
  
    this.transport.onreadystatechange = this.onStateChange.bind(this);
    this.setRequestHeaders();
  
    this.body = this.method == 'post' ? (this.options.postBody || params) : null;
    this.transport.send(this.body);
  </code></pre>
  
  <p>How can I solve the problem?</p>