View Full Version : Download file from servlet with Ajax

22 Nov 2013, 3:58 AM
Hello everybody.

Today is five day, when I try to download my file from server with ExtJS using...
Tomorrow start weekend but there are not success in my work, since the beginning of the week.

I have servlet. And it creating the .xls file and send it to user.

//---xls-file saving---


// gets MIME type of the file
String mimeType = "application/vnd.ms-excel";
// forces download
String headerKey = "Content-Disposition";
String headerValue = String.format("attachment; filename=\"%s\"",
response.setHeader(headerKey, headerValue);
OutputStream outStream = response.getOutputStream();

If I get this file from html page I havent the trouble. But I use ExtJS...

I try catch this file with iframe in Ajax:

url : '/myServlet',
contentType: "application/vnd.ms-excel", // I dont know Nedd it or not
success : function(response,action){
var url = response.responseText; // I dont understand what I must write here
//Ext.Msg.alert('URL is', url);

// creating iframe
var el = document.createElement('iframe');
el.id = 'iframe';
el.src = url; // And here

params: { 'MyParametr': myPar }

I think what me need send the response in my frame, but if I send simple "pesponce" or "response.responseText" it dont work.

In this forum there are a lot of example for this. But I cannot get it work. Please tell me What I need to do in this code, that I can get a my file??

(Sorry for my bad English)

3 Dec 2013, 1:11 PM
You cannot use javascript to prompt for download. You can use Flash or use headers from the server.

14 Jan 2014, 12:34 AM
I solve it, but without "Ext.Ajax".
I create iframe in new ext window, and get my params in it SRC.thank you for yor care)

21 Jan 2014, 2:57 PM
Hi Ange5545, Can you share your solution, how you solved without Ext.Ajax?