我在extjs
中的js文件中有以下代码制作浏览按钮
xtype: 'fileuploadfield',
labelAlign: 'left',
width: 800,
emptyText: 'Select a file',
fieldLabel: 'File ',
buttonText: 'Browse',
fileUpload: true,
id : 'BROWSE_BUTTON', name : 'BROWSE_BUTTON'
将请求传递给Controller
Ext.Ajax.request({
url : 'controller/upload',
method : 'GET',
params : {
fileName : fileName,
docDesc: docDesc
},
headers : {
'Content-Type' : 'multipart/form-data'
},
contentType: false,
上面的代码返回ServletFileUpload.isMultipartContent(request)
false,因此我没有从upload.parseRequest(request)获取。请帮助。
答案 0 :(得分:0)
文件上传不是使用普通的“Ajax”技术执行的,即不使用XMLHttpRequests执行。 More information
有一种棘手的方法,它使用动态生成的隐藏<iframe>
,它插入到文档中,但在收集返回数据后删除。 More information
幸运的是,Ext.Ajax通过upload(form, url, params, options)
方法使用了这种技术。
有一种简单的方法可以将文件上传到服务器:
Ext.onReady(function () {
var win = Ext.create('Ext.window.Window', {
bodyPadding: 5,
renderTo: Ext.getBody(),
items: [
{
xtype: 'form',
items: [
{
xtype: 'filefield',
fieldLabel: 'File',
name: 'file'
}
]
}
],
buttons: [
{
text: 'Save',
handler: function () {
var form = this.up('window').down('form').getForm();
form.submit({
url: 'www.domain.com',
waitMsg: 'Uploading...'
});
}
}
]
});
win.show();
});
使用XMLHttpRequest对象不提交具有文件上载字段的表单 - 而是框架创建并提交临时隐藏<form>
元素,其目标引用临时隐藏<iframe>
。请求标头的Content-Type设置为multipart / form。上传完成且服务器已响应后,临时表单和<iframe>
将被删除。
然后创建一个假的XMLHttpRequest对象,其中包含一个responseText属性(从<iframe>
的内容填充),以确保事件处理程序和回调的工作就像我们使用AJAX提交表单一样。