extjs+SpringMVC上传文件
来源:互联网 发布:淘宝买家数据出售 qq 编辑:程序博客网 时间:2024/06/02 01:21
前台Extjs:
{xtype: 'panel',
border:0, items : [ { xtype : 'form', itemId: 'datasourceId', bodyPadding: 5, title : '数据源', layout: { type:'hbox', padding:'3' }, items : [ { xtype: 'fileuploadfield', fileUpload: true,//chrome浏览器 必须设置为true width:560, labelAlign: 'right', labelWidth: 60, id:'upFile', name: 'upFile', fieldLabel: '*文件名', labelStyle : 'color:red;', allowBlank: false, emptyText:'请选择xls或者xlsx格式的文件', buttonText: '选择文件', regex:/\.xls$|\.xlsx$/, invalidText :'文件格式不正确' }, { xtype: 'button', itemId: 'parseFile', text: '解析文件', handler: 'analysisFile' } ] }
]}
前台Controller:
}/** * 上传文件 * @param btn * @returns {boolean} */analysisFile: function(btn) { var me = btn.up('createfondsimport'); var myform=me.down('form[itemId="datasourceId"]'); var form = myform.getForm(); if(form.isValid()){ var path = form.getValues().upFile; var exp = '\.xls$|\.xlsx$'; console.log("path: "+path); var patt = new RegExp(exp); if(!patt.test(path)){ Ext.Msg.alert('系统提示','导入文件必须是xls文件或者xlsx!!!'); return ; } myform.getEl().mask("正在解析文件,请等待..."); form.submit({ url : 'mvc/dispatch', timeout: 100000, method:'post', params : { action:'FondAction', method:'analysisExcel' }, success : function(response){ var text = response.responseText.result; console.log(response); console.log(text); }, failure : function(response){ myform.getEl().unmask(); Ext.Msg.alert('系统提示','操作失败!'); return ; } }); }}后台Action:@Controller("FondAction")public class FondAction(){@RequestMapping(value = "/analysisExcel")public void upLoad(HttpServletRequest request,HttpServletResponse response) throws IOException {MultipartFile file = ((MultipartHttpServletRequest)request).getFile("upFile");System.out.println("file : \n"+ file);System.out.println("file size: \n"+file.getSize());System.out.println("file Name : \n"+file.getName());System.out.println("file ContentType : \n"+file.getContentType());System.out.println("file OriginalFilename : \n"+file.getOriginalFilename());InputStream fs = null;HSSFWorkbook workbook = null;try {fs = file.getInputStream();workbook = new HSSFWorkbook(fs);log.debug("xssf workbook: \n"+workbook);} catch (IOException e) {system.out.println("******** 异常发生在FondAction.analysisExcel获取文件流时");e.printStackTrace();}HSSFSheet sheet = workbook.getSheetAt(0);HSSFRow row = sheet.getRow(0);HSSFCell cell = row.getCell(0);String value = cell.getStringCellValue();System.out.println("*********************value: \n"+value);// 清空response response.reset(); // 设置response的content type response.setContentType("text/html;charset=utf-8");reponse.getWriter().write(value);}
0 0
- extjs+SpringMVC上传文件
- ExtJs + SpringMVC 文件上传
- springmvc +Extjs+swfUpload上传文件
- ExtJS+SpringMVC文件上传与下载
- Extjs+SpringMvc 上传文件加进度条
- 【ExtJs】ExtJs的文件上传
- Extjs 文件上传
- extjs 上传文件 fileUpload
- ExtJs + Struts2文件上传
- extjs 上传文件 fileUpload
- extjs 文件上传
- Extjs实现文件上传
- extjs实现文件上传
- Extjs文件上传例子
- Extjs文件上传
- Extjs文件上传
- extjs文件上传
- Extjs 实现文件上传
- 关于git、github和.gitignore的一些事
- 2016多校训练Contest10: 1007 cjj's string game hdu5863
- 01_进程和线程
- Maven异常:Could not find artifact
- JAVA注解
- extjs+SpringMVC上传文件
- GCD定时器不起作用原因
- hive内置操作符与函数
- iOS图文混排
- win7系统下如何在虚拟机中安装Linux系统
- NOIP2011 观光公交 解题报告(贪心(贪心一次更新一次))
- celery配置多队列实践笔记
- Android开发之浅谈事件总线框架EventBus和Otto
- 数据结构:用队列实现栈 C++