論壇成員我在extjs 4和JAVA文件上傳有一些問題。圖像文件上傳與extjs 4春天
我使用extjs4和上傳表單代碼
{
xtype: 'filefield',
margin: '10 0 0 5',
width: 296,
fieldLabel: 'Image',
emptyText: 'Select Company logo...',
id: 'cmplogo',
itemId: 'cmplogo',
name: 'cmplogo',
labelWidth: 70
},
{
xtype: 'button',
margin: '10 0 0 90',
width: 89,
text: 'Upload Image',
action: 'btn-upload-img'
},
按鈕上傳圖像具有行動: 'BTN-上傳-IMG' 與功能如下
fileUpload: function(btn) {
var win = btn.up('window');
var form = win.down('form').getForm();
alert('VALUE IS :'+form.getValues());
if(form.isValid()){
form.submit({
url : 'company/UploadFile.action',
waitMsg: 'Uploading your file...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your file has been uploaded.');
}
});
}
},
和定義我的java控制器有以下功能代碼
@RequestMapping(value = "/company/UploadFile.action")
public @ResponseBody
Map<String, ? extends Object> uploadFile(UploadItem uploadItem, BindingResult result) throws Exception {
System.out.println("QUERY TO UPLOAD FILE");
try {
if(result.hasErrors()) {
for(ObjectError error: result.getAllErrors()) {
System.err.println("Error: "+error.getCode()+" - "+error.getDefaultMessage());
}
}
else
{
MultipartFile file = uploadItem.getFileData();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
if(file.getSize() > 0) {
inputStream = file.getInputStream();
if(file.getSize() > 10000) {
System.out.println("FILE SIZE:::"+file.getSize());
}
System.out.println("SIZE ::"+file.getSize());
fileName = "E:\\images\\"+file.getOriginalFilename();
outputStream = new FileOutputStream(fileName);
System.out.println("FILE NAME AND PATH IS ::"+fileName);
System.out.println("FILENNAME ::"+file.getOriginalFilename());
int readBytes = 0;
byte[] buffer = new byte[10000];
while((readBytes = inputStream.read(buffer, 0, 10000)) !=-1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.close();
inputStream.close();
}
}
} catch (Exception e) {
return getModelMapError("Error trying to read city");
}
return null;
}
不要知道我上面的代碼有什麼問題。 我螢火控制檯給我下面的錯誤
**uncaught exception: You're trying to decode an invalid JSON String: <pre>{"message":"Error trying to read city","success":false}</pre>**
請建議我一些解決方案,我可以嘗試讓我的錯誤很快得到解決。
是你能找出你的情況的解決方案? – pacman 2012-04-10 16:38:20