Having trouble sending a zip file from a Java servlet to a JavaScript client. The zip archive is generated successfully on disk, but there's an issue with transferring it to the client.
The code snippet responsible for sending the file in the doPost
method is as follows:
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();
Here's the Ajax request made by the client:
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 )
} );
The browser console displays the following error message:
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
When checking the Source
tab, I encounter a Failed to load resource
message after the last line of the following code snippet:
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);
Looking for guidance on resolving this issue. Any suggestions?