java – 使用Ext JS 6下载文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 使用Ext JS 6下载文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2049字,纯文字阅读大概需要3分钟。
内容图文
![java – 使用Ext JS 6下载文件](/upload/InfoBanner/zyjiaocheng/795/1265c188722d4934882a5a51ffcc54d7.jpg)
我正在尝试使用基于此帖子的Ext JS 6组件从服务器下载文件:download a file via Ext js 4
这是组件代码:
Ext.define('Aft.view.search.FileDownload', {
extend: 'Ext.Component',
alias: 'widget.acw-fileDownload',
autoEl: {
tag: 'iframe',
cls: 'x-hidden',
src: Ext.SSL_SECURE_URL
},
load: function(config){
var e = this.getEl();
e.dom.src = config.url +
(config.params ? '?' + Ext.urlEncode(config.params) : '');
e.dom.onload = function() {
if(e.dom.contentDocument.body.childNodes[0].wholeText == '404') {
console.
Ext.create('Acw.view.commons.notifications.Error', {
html: 'The document you are after can not be found on the server.',
closeAll: true
}).show();
}
}
}
});
这是获取文件的调用:
doExportData: function(){
this.getView().load({
url: '/aft/faults/download-file'
});
这是Spring rest服务返回一个模拟文件:
@RequestMapping(value = "/download-file", method = RequestMethod.POST)
public void downloadFilePost(HttpServletResponse response) {
String csvFileName = "searchFaults.csv";
response.setContentType("text/csv");
// creates mock data
String headerKey = "Content-Disposition";
String headerValue = String.format("attachment; filename=\"%s\"", csvFileName);
response.setHeader(headerKey, headerValue);
try {
CSVWriter writer = new CSVWriter(response.getWriter(), '\t');
String[] entries = "first#second#third".split("#");
writer.writeNext(entries);
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但是,当我打电话时,我得到这样的东西:
[E] Ext.JSON.decode(): You’re trying to decode an invalid JSON String: “first” “second” “third”
Uncaught Error: You’re trying to decode an invalid JSON String: “first” “second” “third”
似乎某些东西到达客户端,但它试图将其解析为JSON.尽管如此,如果我将RequestMethod更改为GET并直接在浏览器中键入URL,我会得到该文件,这使我认为标题是正确的.
有人可以帮我解决这个问题,或者你是否使用不同的方法/组件从服务器下载文件?
解决方法:
只需使用以下代码即可下载该文件:
doExportData: function(config){
window.location.assign(config.url +
(config.params ? '?' + Ext.urlEncode(config.params) : ''));
});
内容总结
以上是互联网集市为您收集整理的java – 使用Ext JS 6下载文件全部内容,希望文章能够帮你解决java – 使用Ext JS 6下载文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。