上传excel文件读取内容可以异步吗 | 您所在的位置:网站首页 › excel文件的读取 › 上传excel文件读取内容可以异步吗 |
可以。ajaxfileupload.js插件可以实现Excel的异步上传,所以上传excel文件读取内容可以异步。MicrosoftExcel是Microsoft为使用Windows和AppleMacintosh操作系统的电脑编写的一款电子表格软件。传其他参数 ajax文件上传怎么传其他参数,Ajax进行文件与其他参数的上传功能 光启元 转载 关注 0点赞·945人阅读 记得前一段时间,为了研究Ajax文件上传,找了很多资料,在网上看到的大部分是form表单的方式提交文件,对于Ajax方式提交文件并且也要提交表单中其他数据,发现提及的并不是很多,后来在同事的帮助下,使用ajaxfileupload最终完成了文件上传与其他提交的操作,现在分享给大家,希望大家能有有所帮助。本文主要介绍了使用Ajax进行文件与其他参数的上传功能(java开发),非常不错,具有参考借鉴价值,需要的朋友参考下吧,希望能帮助到大家。 文件上传: 操作步骤: 1 导入jar包: 我们在使用文件上传时,需要使用到两个jar包,分别是commons-io与commons-fileupload,在这里我使用的两个版本分别是2.4与1.3.1版本的,需要使用JS文件与jar包最后会发给大家一个连接(如何失效请直接我给留言,我会及时更改,谢谢)。 2 修改配置文件: 当我们导入的jar包是不够的,我们需要使用到这些jar包,由于我当时使用的是SSM框架,所以我是在application-content.xml中配置一下CommonsMultipartResolver,具体配置方法如下: 104857600 4096 3 JSP文件: 大家对form表单提交问价的方式很熟悉,但是我们有很多情况下并不能直接使用form表单方式直接提交。这时候我们就需要使用Ajax方式提交,Ajax有很多的好处,比如当我们不需要刷新页面获希望进行局部刷新的时候,我们就可以使用Ajax。 JSP页面中引入的script代码script function ajaxFileUpload() { $("#loading").ajaxStart(function(){ $(this).show() })//开始上传文件时显示一个图片 .ajaxComplete(function(){ $(this).hide() })//文件上传完成将图片隐藏起来 $.ajaxFileUpload({ url:'AjaxImageUploadAction.action',//用于文件上传的服务器端请求地址 secureuri:false,//一般设置为false fileElementId:'imgfile',//文件上传空间的id属性 input type="file" id="imgfile" name="file" / dataType: 'json',//返回值类型 一般设置为json success: function (data, status) //服务器成功响应处理函数 { alert(data.message)//从服务器返回的json中取出message中的数据,其中message为在struts2中定义的成员变量 if(typeof(data.error) != 'undefined') { if(data.error != '') { alert(data.error) }else { alert(data.message) } } }, error: function (data, status, e)//服务器响应失败处理函数 { alert(e) } } ) return false } /script struts.xml配置文件中的配置方法: struts package name="struts2" extends="json-default" action name="AjaxImageUploadAction" class="com.test.action.ImageUploadAction" result type="json" name="success" param name="contentType"text/html/param /result result type="json" name="error" param name="contentType"text/html/param /result /action /package /struts 上传处理的Action ImageUploadAction.action package com.test.action import java.io.File import java.io.FileInputStream import java.io.FileOutputStream import java.util.Arrays import org.apache.struts2.ServletActionContext import com.opensymphony.xwork2.ActionSupport @SuppressWarnings("serial") public class ImageUploadAction extends ActionSupport { private File imgfile private String imgfileFileName private String imgfileFileContentType private String message = "你已成功上传文件" public File getImgfile() { return imgfile } public void setImgfile(File imgfile) { this.imgfile = imgfile } public String getImgfileFileName() { return imgfileFileName } public void setImgfileFileName(String imgfileFileName) { this.imgfileFileName = imgfileFileName } public String getImgfileFileContentType() { return imgfileFileContentType } public void setImgfileFileContentType(String imgfileFileContentType) { this.imgfileFileContentType = imgfileFileContentType } public String getMessage() { return message } public void setMessage(String message) { this.message = message } @SuppressWarnings("deprecation") public String execute() throws Exception { String path = ServletActionContext.getRequest().getRealPath("/upload/mri_img_upload") String[] imgTypes = new String[] { "gif", "jpg", "jpeg", "png","bmp" } try { File f = this.getImgfile() String fileExt = this.getImgfileFileName().substring(this.getImgfileFileName().lastIndexOf(".") + 1).toLowerCase() /* if(this.getImgfileFileName().endsWith(".exe")){ message="上传的文件格式不允许!!!" return ERROR }*/ /** * 检测上传文件的扩展名是否合法 * */ if (!Arrays.String asList(imgTypes).contains(fileExt)) { message="只能上传 gif,jpg,jpeg,png,bmp等格式的文件!" return ERROR } FileInputStream inputStream = new FileInputStream(f) FileOutputStream outputStream = new FileOutputStream(path + "/"+ this.getImgfileFileName()) byte[] buf = new byte[1024] int length = 0 while ((length = inputStream.read(buf)) != -1) { outputStream.write(buf, 0, length) } inputStream.close() outputStream.flush() } catch (Exception e) { e.printStackTrace() message = "文件上传失败了!!!!" } return SUCCESS } } 转载,仅供参考。 欢迎分享,转载请注明来源:内存溢出 原文地址:https://outofmemory.cn/tougao/6041117.html |
CopyRight 2018-2019 实验室设备网 版权所有 |