I need to upload a file from extjs page, via form submit, to the server. I am able to do it with simple HTML page to servlet but using extjs (v4.2) i am not getting file in my servlet when i pars request. Servlet recognizes multipart page but nothing comes with the call. Can anyone tell me what I am doing wrong in my code?


Ext.define('Capa.view.GIExpenseUploadPopup', {
extend: 'Ext.window.Window',
title: 'This is a Window with a Form',
height: 200,
id: 'giExpenseUploadPopup',
width: 400,
layout: 'fit',
items: [{ // the form is an item of the window
id: 'giExpenseUploadPopupForm',
name: 'giExpenseUploadPopupForm',
title: 'Add administration users',
width: 740,
height: 480,
iconCls: 'icon-grid',
animCollapse: false,
constrainHeader: true,
xtype: 'form',
isUpload: true,
fileUpload: true,
bodyPadding: 15,
enctype: 'multipart/form-data',
method: 'post',
headers: {'Content-Type':'multipart/form-data; charset=UTF-8'},
url: Capa.Config.jsonBase() + '?command=' + 'GI_EXPENSE_UPLOAD',
items: [
{
xtype: 'filefield',
fieldLabel: 'fileupload',
name:'giExpenseUploadFile',
//width:100,
allowBlank:false,
disabled:false,
id : 'giExpenseUploadFile'
},
{
xtype: 'numberfield',
anchor: '100%',
fieldLabel: 'Numeric field',
id : 'giText',
name:'giText',
maxValue: 99,
minValue: 0
}

],
buttons: [{
text: 'Submit',
handler: function() {
var form = this.up('form').getForm();
var fileInput = Ext.getCmp('giExpenseUploadFile');
var files = fileInput.files;
console.log("****************************************");
alert("files ; " + files);
console.log("****************************************");
var fileToUpload = fileInput;
alert("form submittion");
if (form.isValid()) {
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', action.result.message);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response');
}
});
} else {
Ext.Msg.alert( "Error!", "Your form is invalid!" );
}
}
}]
}]
}).show();




servlet,

@MultipartConfig(fileSizeThreshold=1024*1024*2, // 2MB
maxFileSize=1024*1024*10, // 10MB
maxRequestSize=1024*1024*50) // 50MB
public class GIExpenseUploadCmd extends AjaxCommand {
private static final String SAVE_DIR = "uploadFiles";
public void invoke() throws Exception
{
for(Part part : request.getParts()){
System.out.println("PN: "+ part.getName());
Collection<String> headers = part.getHeaders("content-disposition");
if (headers == null)
continue;
for(String header : headers){
System.out.println("*=> CDH: " + header);
}
}


Enumeration<String> parameterNames =request.getParameterNames();


while (parameterNames.hasMoreElements()) {


String paramName = parameterNames.nextElement();
System.out.println("&&&&&&&&&&&&& : = "+ paramName);


String[] paramValues = request.getParameterValues(paramName);
for (int i = 0; i < paramValues.length; i++) {
String paramValue = paramValues[i];
System.out.println("$$$$$$$$$$$$$$$$$ : val : " + paramValue );

}


}



Part filePart = request.getPart("giExpenseUploadFile");
String appPath = request.getServletContext().getRealPath("");
String savePath = appPath + File.separator + SAVE_DIR;
File fileSaveDir = new File(savePath);
if (!fileSaveDir.exists()) {
fileSaveDir.mkdir();
}
for (Part part : request.getParts()) {
String fileName = extractFileName(part);
// refines the fileName in case it is an absolute path
fileName = new File(fileName).getName();
part.write(savePath + File.separator + fileName);
}

System.out.println("message : Upload has been done successfully!");

jsonResponse.put("METRICS", metrics);
jsonResponse.put("NUM_OF_RECORDS_IMPORTED", 1);
}

/**
* Extracts file name from HTTP header content-disposition
*/
private String extractFileName(Part part) {
String contentDisp = part.getHeader("content-disposition");
String[] items = contentDisp.split(";");
for (String s : items) {
if (s.trim().startsWith("filename")) {
return s.substring(s.indexOf("=") + 2, s.length()-1);
}
}
return "";
}


}

please help me