我无法读取 java 代码中的文件内容,通过 extjs 代码传递给 java spring 控制器
I am not been able to read the file contents in java code, passed through extjs code to java spring controller
// Here's my extjs code
Ext.define('ArticulationAgreement.view.Filechooser',{
extend : 'Ext.form.Panel',
alias : 'widget.filechooser',
mixins: ['Deft.mixin.Injectable', 'Deft.mixin.Controllable'],
//controller : ['ArticulationAgreement.controller.FilechooserController'],
width : 1500,
height : 300,
bodyPadding: '10 10 0',
frame: true,
initComponent : function(){
var me = this;
Ext.apply(me, {
title : 'Add the CSV Files',
defaults:
{
anchor: '30%',
allowBlank: false,
msgTarget: 'side',
labelWidth: 100
},
items : [
{
xtype: 'filefield',
id: 'form-file',
emptyText: 'Select a File',
//maxLength : '30',
fieldLabel: 'File Selected',
name: 'fpath',
buttonText: 'upload file'
},
{
text : 'Save File',
xtype : 'button',
width: 75,
itemId : 'save',
layout : 'hbox',
anchor : '5%',
handler : function(){
//console.log(this.up('form').down('textfield[name=file-path]').value);
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url : 'http://localhost:8080/ssp/api/upload.action',
waitMsg: 'Uploading your file',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your file has been uploaded.'+fp.responseText);
}
});
}
}
},
{
text : 'Reset',
xtype : 'button',
width : 75,
layout : 'hbox',
anchor : '5%',
handler : function(){
this.up('form').getForm().reset();
}
}
]
});
return me.callParent(arguments);
}
});
//这是我的spring控制器代码
@RequestMapping(method = RequestMethod.POST)
public
ResponseEntity<String> uploadFile(FileUploadBean uploadItem, BindingResult result) throws Exception {
System.out.println("QUERY TO UPLOAD FILE");
try {
MultipartFile file = uploadItem.getFile();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
//Exception on next line:
System.out.println("Test upload: " + uploadItem.getFile().getOriginalFilename());
//rest of the code
return null;
}
//我在 java 控制器中遇到异常,它在 extjs 代码中给出了响应——
//Uncaught Ext.JSON.decode(): 你试图解码一个无效的 JSON 字符串:
//如果可能请帮助我,在此先感谢。
//Extjs Code
{
xtype: 'filefield',
emptyText: 'Select a File',
//maxLength : '30',
fieldLabel: 'File Selected',
name: 'file',//change in only this line was needed
buttonText: 'Choose File'
}
//Spring Controller Code
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody String uploadFile(FileUploadBean uploadItem, BindingResult result) throws Exception {
System.out.println("QUERY TO UPLOAD FILE");
try {
CommonsMultipartFile file = uploadItem.getFile();//changed line
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
System.out.println("Test upload: " + uploadItem.getFile().getOriginalFilename());
//rest of the code
}
return null;
}
// Here's my extjs code
Ext.define('ArticulationAgreement.view.Filechooser',{
extend : 'Ext.form.Panel',
alias : 'widget.filechooser',
mixins: ['Deft.mixin.Injectable', 'Deft.mixin.Controllable'],
//controller : ['ArticulationAgreement.controller.FilechooserController'],
width : 1500,
height : 300,
bodyPadding: '10 10 0',
frame: true,
initComponent : function(){
var me = this;
Ext.apply(me, {
title : 'Add the CSV Files',
defaults:
{
anchor: '30%',
allowBlank: false,
msgTarget: 'side',
labelWidth: 100
},
items : [
{
xtype: 'filefield',
id: 'form-file',
emptyText: 'Select a File',
//maxLength : '30',
fieldLabel: 'File Selected',
name: 'fpath',
buttonText: 'upload file'
},
{
text : 'Save File',
xtype : 'button',
width: 75,
itemId : 'save',
layout : 'hbox',
anchor : '5%',
handler : function(){
//console.log(this.up('form').down('textfield[name=file-path]').value);
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url : 'http://localhost:8080/ssp/api/upload.action',
waitMsg: 'Uploading your file',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your file has been uploaded.'+fp.responseText);
}
});
}
}
},
{
text : 'Reset',
xtype : 'button',
width : 75,
layout : 'hbox',
anchor : '5%',
handler : function(){
this.up('form').getForm().reset();
}
}
]
});
return me.callParent(arguments);
}
});
//这是我的spring控制器代码
@RequestMapping(method = RequestMethod.POST)
public
ResponseEntity<String> uploadFile(FileUploadBean uploadItem, BindingResult result) throws Exception {
System.out.println("QUERY TO UPLOAD FILE");
try {
MultipartFile file = uploadItem.getFile();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
//Exception on next line:
System.out.println("Test upload: " + uploadItem.getFile().getOriginalFilename());
//rest of the code
return null;
}
//我在 java 控制器中遇到异常,它在 extjs 代码中给出了响应—— //Uncaught Ext.JSON.decode(): 你试图解码一个无效的 JSON 字符串: //如果可能请帮助我,在此先感谢。
//Extjs Code
{
xtype: 'filefield',
emptyText: 'Select a File',
//maxLength : '30',
fieldLabel: 'File Selected',
name: 'file',//change in only this line was needed
buttonText: 'Choose File'
}
//Spring Controller Code
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody String uploadFile(FileUploadBean uploadItem, BindingResult result) throws Exception {
System.out.println("QUERY TO UPLOAD FILE");
try {
CommonsMultipartFile file = uploadItem.getFile();//changed line
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
System.out.println("Test upload: " + uploadItem.getFile().getOriginalFilename());
//rest of the code
}
return null;
}