1.首先引入FileUploadField.js和FileUploadField.css,网上应该有现成的文件,可以直接下载
2.前台
var InfoForm = new Ext.form.FormPanel({
frame: true,
autoHeight: true,
width: 400,
defaultType: 'textfield',
labelWidth: 90,
waitMsgTarget: true,
fileUpload: true, //这句必须有
items:[{
xtype: 'fileuploadfield',
fieldLabel: '上传文件',
buttonText:'浏览',
width:'250',
style: 'padding-left: 10px',
id: 'uploadCertId',
name: 'upload'
}],
buttons: [{
text: '上传',
handler: function() {
if(!uploadForm.getForm().isValid()) {
InfoForm.getForm().submit({
url: 'dataUploadAction.asp?method=upload',
method: 'post',
waitMsg: '正在请求上传,请稍后......',
success: function(form,action) {
//上传成功后的操作
},
failure: function(form,action) {
//上传失败后的操作
},
params: {
txnId: '20110',
subTxnId: '00'
}
});
}
}
}]
})
2.后台接收参数(第一种是上传多个文件时声明一个List接收)
//上传文件
private List<File> upload; || private File upload;
// 上传文件名
private String[] uploadFileName; || private String uploadFileName;
// 上传文件的MIME类型
private String[] uploadContentType; || private String uploadContentType;