extjsspring文件上传
我有外部表单面板,其中包括文件上传项目。代码如下所示:extjsspring文件上传,extjs,file-upload,extjs3,Extjs,File Upload,Extjs3,我有外部表单面板,其中包括文件上传项目。代码如下所示: fp = new Ext.FormPanel({ fileUpload: true, autoHeight: true, bodyStyle: 'padding: 10px 10px 0 10px;', labelWidth: 50, defaults: { anchor: '95%', allowB
fp = new Ext.FormPanel({
fileUpload: true,
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [
{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select excel file',
fieldLabel: 'File',
name: 'file',
buttonText: 'Choose File',
buttonCfg: {
iconCls: 'upload-icon'
}
}
],
buttons: [{
text: 'Load',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: myURL,
waitMsg: 'Uploading your photo...',
success: function(fp, o){
// I want to get loaded excel data list
},
failure : function(fp,o)
{
console.log('error');
}
});
}
}
}]
});
我有spring控制器和一些用于处理上传的excel数据的服务。上传excel后,我在excel上迭代数据并将其放入列表中
@RequestMapping("/uploadExcel")
@ResponseBody
public Map<String, ? extends Object> uploadExcellData(@RequestParam("file") MultipartFile file)
{
Map<String, Object> result = new HashMap<String,Object>();
try
{
result = uploadService(file);
}
catch(Exception ex)
{
logger.error(ex.getMessage(), ex);
}
return result;
}
public Map<String,Object> uploadService(MultipartFile argFile) throws BLOException, DAOException
{
Map<String,Object> result = new HashMap<String,Object>(3);
List importExcelList = null;
try
{
if (!argFile.isEmpty())
{
importExcelList = parseExcelAndCreateListFunction(argFile.getInputStream());
result.put("total", new Integer(importExcelList.size()));
result.put("success", true);
result.put("data", importExcelList);
}
}
catch (IOException e)
{
logger.error(e.getMessage(), e);
}
return result;
}
@RequestMapping(“/uploadExcel”)
@应答器
公共映射上载ExcelData(@RequestParam(“文件”)多部分文件)
{
映射结果=新的HashMap();
尝试
{
结果=上传服务(文件);
}
捕获(例外情况除外)
{
logger.error(例如getMessage(),例如);
}
返回结果;
}
公共映射上载服务(MultipartFile argFile)引发BLOException、DAOException
{
映射结果=新的HashMap(3);
列表导入Cellist=null;
尝试
{
如果(!argFile.isEmpty())
{
importExcelList=parseExcelAndCreateListFunction(argFile.getInputStream());
结果.put(“总计”,新整数(importeCellist.size());
结果。放置(“成功”,真);
结果。输入(“数据”,输入大提琴家);
}
}
捕获(IOE异常)
{
logger.error(e.getMessage(),e);
}
返回结果;
}
当我运行此代码时,我得到“NetworkError:404未找到”
”。
我想在表单提交后返回excel数据列表。我不能这么做。如何在提交回调时获取excel数据列表?我想您需要返回其他参数并签入
success
methodaction
参数。请检查。我更新了如下java文件:
@RequestMapping("/uploadExcel")
@ResponseBody
public void uploadExcellData(@RequestParam("file") MultipartFile file, HttpServletResponse response)
{
Map<String, Object> result = new HashMap<String,Object>();
try
{
result = uploadService(file);
}
catch(Exception ex)
{
logger.error(ex.getMessage(), ex);
}
response.setContentType("text/html; charset=UTF-8");
response.getWriter().write("{success:true, total:'"+result.size()+"', data:'"+result+"'}");
}
public List uploadService(MultipartFile argFile) throws BLOException, DAOException
{
List importExcelList = null;
try
{
if (!argFile.isEmpty())
{
importExcelList = parseExcelAndCreateListFunction(argFile.getInputStream());
}
}
catch (IOException e)
{
logger.error(e.getMessage(), e);
}
return importExcelList;
}
fp = new Ext.FormPanel({
fileUpload: true,
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [
{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select excel file',
fieldLabel: 'File',
name: 'file',
buttonText: 'Choose File',
buttonCfg: {
iconCls: 'upload-icon'
}
}
],
buttons: [{
text: 'Load',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: myURL,
waitMsg: 'Uploading your photo...',
success: function(fp, o){
var resData = Ext.util.JSON.decode(o.result.data);
// I can iterate resData
},
failure : function(fp,o)
{
Ext.MessageBox.alert("Failure", "your error message");
}
});
}
}
}]
});
如上所述,我解决了我的问题。关于附加参数,你是什么意思?我可以把额外的参数放在哪里和什么地方?因此在
success
方法中的代码中,您会收到两个参数:fp,o
所以-您可以检查firebugo.result
-我想您会在那里看到数据
。我还无法找到success
方法。上传并迭代文件后,我收到NetworkError
。错误在js端,对吗?然后转到failure
方法?你在firebug中看到了什么?是的,js端出现了错误。不转到故障
方法。当它从控制器返回时,给出404 NetworkError
。我调试了一些不同的东西,它将
标记放在返回值上,我认为这会导致错误,但我不知道如何修复它。