PDA

View Full Version : How to display text file returned from servlet, in browser?



dissectcode
11 Aug 2012, 10:44 AM
I know this question is a repeat but I am doing everything that I should be and still blocked. I *must* be missing something. The "inline" part isn't working in Content-Dispostion in Extjs :


In my servlet, I write to the response header first :


response.setHeader("Content-Disposition", "inline;attachment;filename=" + fileName);


and then write the file to the response output, as normal inside the Java servlet code. I read on a forum that including "inline" will try inline first, and if it can't open inline, the save as... will pop up. So that sounded promising.

If I include "inline" then nothing happens in the browser for text files, not even a pop up or save as... but for other file types, it works as expected with save as... Further, when I only include "attachment" in the header, it of course always pops up save as...for plain text.

Here is my Extjs code for calling the servlet :



DownloadFile(fileObj.value);
function DownloadFile(filename) {
var body = Ext.getBody();

// create a hiddle frame
var frame = body.createChild({
tag: 'iframe',
cls: 'x-hidden',
id: 'iframe',
name: 'iframe'
});

//create hidden form with download as action

var form = body.createChild({
tag: 'form',
cls: 'x-hidden',
id: 'form',
action: '/ctkb-spring/cmsFilePreview',
target: 'iframe'
});

// submit the form to initiate the downloading
form.dom.submit();
}


So it "works" but I don't want to get in trouble for not doing it like the legacy code. thank you

OH, I also tried all 3 combinations of Content-Disposition: inline; attachment - inline - attachment

If there is a different method for doing this in IE, please let me know as I have to support both FF and IE

scottmartin
5 Sep 2012, 8:08 PM
You should be able to just specify the file:



Ext.onReady(function() {
myPanel = Ext.create('Ext.Panel', {
width: 300,
height: 150,
title: 'Title',
layout: 'vbox',
frame: true,
renderTo: Ext.getBody(),
items: [
{
xtype: 'button',
text: 'Click to open TEXT window',
handler: function(b, e) {
var myWin = Ext.create("Ext.window.Window", {
title: 'HTML Window',
modal: true,
html: '<iframe src="../../extjs4/license.txt" width="100%" height="100%" ></iframe>',
width: 700,
height: 500
});
myWin.show();
}
}
]
});
});


Scott.