我用extjs+struts1.2做文件上传时,当文件上传成功后,却弹出了下载框,而Ext里提交后的回调函数却不能响应,为什么呢? 我使用了oreilly的COS上传组件。
前台代码是:
var upwin = new Ext.Window({ //一个窗口
width:350,
title: 'Excel文件上传',
height:180,
closeAction:'close', //关闭图标 hide / close
plain: true,
modal:true,
autoScroll:true, //自动滚动
containerScroll: false,
layout: 'fit',
items:[
new Ext.form.FormPanel({
labelAlign: 'right',
labelWidth: 60,
frame:true,
url: 'pushMgrAction.do?method=uploadFile',//fileUploadServlet
width: 300,
height:200,
fileUpload: true,
items: [{
xtype: 'textfield',
fieldLabel: '文件名',
name: 'file',
width: '250',
inputType: 'file'//文件类型
}]
})
],
buttonAlign : 'center',
buttons: [{
text: '导 入',
handler: function() {
upform.getForm().submit({
success: function(form, action){
Ext.Msg.alert('信息', action.result.msg);
},
failure: function(){ Ext.Msg.alert('错误', '文件导入失败');},
waitMsg : '正在导入数据,请等待...'
});
}
},{ text: '关 闭',handler: function(){ upwin.close(); }
}]
});
upwin.show();
}
var upform = ;
action中的代码是:
response.setContentType("text/json; charset=gb2312");
MultipartRequest multi = new MultipartRequest(request, saveDirectory, maxPostSize, "gb2312");
XlsImport xlssave = new XlsImport();
//输出反馈信息
Enumeration files = multi.getFileNames();
while (files.hasMoreElements()) {
String name = (String)files.nextElement();
File f = multi.getFile(name);
if(f!=null){
String fileName = multi.getFilesystemName(name);
String lastFileName= saveDirectory+"\\" + fileName;
java.io.File tmpfile = new java.io.File(lastFileName);
if (tmpfile.exists()) {
xlssave.xlsToDB(user.getEmpid(), lastFileName);
if(xlssave.getErrors().equals("")){
redata = "{success:true,msg:'成功导入了"+xlssave.getRowCount()+"条数据!'}" ;
}else{
redata = "{success:false,msg:'"+xlssave.getErrors().toString()+"'}";
}
}
tmpfile.delete();
}
}
out.write(redata);
out.flush();
--------------------------------------------------------------------------------
分享到:
相关推荐
NULL 博文链接:https://jiangtie.iteye.com/blog/1003878
NULL 博文链接:https://frankco.iteye.com/blog/1685118
NULL 博文链接:https://pope12389.iteye.com/blog/1247893
NULL 博文链接:https://vb2005xu.iteye.com/blog/387621
博文链接:https://wdfan.iteye.com/blog/197543
NULL 博文链接:https://vb2005xu.iteye.com/blog/1066661
NULL 博文链接:https://kenken0y.iteye.com/blog/504550
NULL 博文链接:https://vb2005xu.iteye.com/blog/2099653
NULL 博文链接:https://vb2005xu.iteye.com/blog/319876
博文链接:https://balaschen.iteye.com/blog/82579
博文链接:https://jackzhangyunjie.iteye.com/blog/202349
NULL 博文链接:https://hnzhoujunmei.iteye.com/blog/1033244
NULL 博文链接:https://yiqieanhao.iteye.com/blog/1744598
NULL 博文链接:https://danwind.iteye.com/blog/429903
NULL 博文链接:https://superior.iteye.com/blog/710595
NULL 博文链接:https://coolzhi.iteye.com/blog/614524