EXT 上传文件时加上fileUpload: true出错的问题。
2013-07-03 08:46
483 查看
Ext做文件上传的时候发现,如果上传成功后从后台取返回信息,出现错误。
Js代码
var importForm = new Ext.FormPanel({
labelAlign:'right',
buttonAlign:'right',
frame:true,
title: '',
bodyStyle:'padding:5px 5px',
width:450,
url:'importAction.do?method=importAlarmRule',
fileUpload: true,
items: [{
xtype: 'textfield',
fieldLabel: '<bean:message key="aloes.message.resource.import.file" />',
name: 'importFile',
width: 270,
height:20,
allowBlank:false,
blankText: '<bean:message key="aloes.message.resource.import.file.select" />',
inputType: 'file'//文件类型
}],
buttons: [{
text: '<bean:message key="button.save" />',
handler: function() {
importForm.getForm().submit({
success: function(fileform, action){
if(action.result.success == 'true'){
Ext.Msg.alert('<bean:message key="info.header" />', '<bean:message key="aloes.message.resource.import.success" />',function(){
importWin.close();
});
}else if(action.result.failure == 'formatError'){
Ext.Msg.alert('Error', '<bean:message key="aloes.message.resource.import.failed" />'+action.result.info);
}
},
failure: function(){
Ext.Msg.alert('<bean:message key="message.error" />', '<bean:message key="aloes.message.resource.import.failed" />');
}
});
}
},{
text: '<bean:message key="button.cancel" />',
handler: function() {
importWin.close();
}
}]
});
var importWin = new Ext.Window({
id:'import-window',
title: '<bean:message key="aloes.message.resource.import" />',
closable:true,
width:460,
maximizable:false,
modal:true,
plain:true,
items:[importForm]
});
importWin.show();
后台的java代码往前台送数据的时候:
resultStr.append("{'failure':'false','success':'true'}");
response.setContentType(" text/html;charset=utf-8 ");
response.getWriter().print(resultStr);
contentType必须为:" text/html;charset=utf-8 "
而不能为:" text/xml;charset=utf-8 "
否则前台会报错。
Js代码
var importForm = new Ext.FormPanel({
labelAlign:'right',
buttonAlign:'right',
frame:true,
title: '',
bodyStyle:'padding:5px 5px',
width:450,
url:'importAction.do?method=importAlarmRule',
fileUpload: true,
items: [{
xtype: 'textfield',
fieldLabel: '<bean:message key="aloes.message.resource.import.file" />',
name: 'importFile',
width: 270,
height:20,
allowBlank:false,
blankText: '<bean:message key="aloes.message.resource.import.file.select" />',
inputType: 'file'//文件类型
}],
buttons: [{
text: '<bean:message key="button.save" />',
handler: function() {
importForm.getForm().submit({
success: function(fileform, action){
if(action.result.success == 'true'){
Ext.Msg.alert('<bean:message key="info.header" />', '<bean:message key="aloes.message.resource.import.success" />',function(){
importWin.close();
});
}else if(action.result.failure == 'formatError'){
Ext.Msg.alert('Error', '<bean:message key="aloes.message.resource.import.failed" />'+action.result.info);
}
},
failure: function(){
Ext.Msg.alert('<bean:message key="message.error" />', '<bean:message key="aloes.message.resource.import.failed" />');
}
});
}
},{
text: '<bean:message key="button.cancel" />',
handler: function() {
importWin.close();
}
}]
});
var importWin = new Ext.Window({
id:'import-window',
title: '<bean:message key="aloes.message.resource.import" />',
closable:true,
width:460,
maximizable:false,
modal:true,
plain:true,
items:[importForm]
});
importWin.show();
var importForm = new Ext.FormPanel({ labelAlign:'right', buttonAlign:'right', frame:true, title: '', bodyStyle:'padding:5px 5px', width:450, url:'importAction.do?method=importAlarmRule', fileUpload: true, items: [{ xtype: 'textfield', fieldLabel: '<bean:message key="aloes.message.resource.import.file" />', name: 'importFile', width: 270, height:20, allowBlank:false, blankText: '<bean:message key="aloes.message.resource.import.file.select" />', inputType: 'file'//文件类型 }], buttons: [{ text: '<bean:message key="button.save" />', handler: function() { importForm.getForm().submit({ success: function(fileform, action){ if(action.result.success == 'true'){ Ext.Msg.alert('<bean:message key="info.header" />', '<bean:message key="aloes.message.resource.import.success" />',function(){ importWin.close(); }); }else if(action.result.failure == 'formatError'){ Ext.Msg.alert('Error', '<bean:message key="aloes.message.resource.import.failed" />'+action.result.info); } }, failure: function(){ Ext.Msg.alert('<bean:message key="message.error" />', '<bean:message key="aloes.message.resource.import.failed" />'); } }); } },{ text: '<bean:message key="button.cancel" />', handler: function() { importWin.close(); } }] }); var importWin = new Ext.Window({ id:'import-window', title: '<bean:message key="aloes.message.resource.import" />', closable:true, width:460, maximizable:false, modal:true, plain:true, items:[importForm] }); importWin.show();
后台的java代码往前台送数据的时候:
resultStr.append("{'failure':'false','success':'true'}");
response.setContentType(" text/html;charset=utf-8 ");
response.getWriter().print(resultStr);
contentType必须为:" text/html;charset=utf-8 "
而不能为:" text/xml;charset=utf-8 "
否则前台会报错。
相关文章推荐
- FileUpload控件上传大文件时不进断点出错的问题
- commons-fileupload 上传文件乱码问题
- strust2 form标签加上validate="true"后出错,求问问题原因
- pdf文件上传成功后,下载出错的问题原因
- Struts2文件上传在配置fileUpload拦截器中设置文件大小无效的问题
- commons-fileupload 上传文件乱码问题
- java linux和windows下文件路径间隔符的写法——解决linux下程序在windows下运行时的上传文件出错问题
- FileUpload 服务器控件示例,Asp.net上传文件,找不到上传文件的控件问题,(转)
- strust2 form标签加上validate="true"后出错,求问问题原因
- 解决:上传文件按钮样式,fileupload 样式,同时解决后台得不到上传文件的信息问题
- jsp中用fileupload组件上传文件遇到的问题
- commons-fileupload 文件上传问题
- strust2 form标签加上validate="true"后出错,求问问题原因
- 用Apache的commons-fileupload组件上传文件时,普通字段编码出错
- ASP.NET FileUpload文件上传路径问题
- commons-fileupload 上传文件乱码问题
- strust2 form标签加上validate="true"后出错,求问问题原因
- strust2 form标签加上validate="true"后出错,求问问题原因
- strust2 form标签加上validate="true"后出错,求问问题原因
- 解决Apache的文件上传组件FileUpLoad的中文乱码问题