DropZone图片上传控件的使用
前台代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script type="text/javascript" src="Dropzone/dropzone.min.js"></script>
<link rel="stylesheet" type="text/css" href="Dropzone/css/basic.css"><link>
<link rel="stylesheet" type="text/css" href="Dropzone/css/dropzone.css"><link> <script> Dropzone.options.dropzoneForm = {
//添加上传取消和删除预览图片的链接,默认不添加
addRemoveLinks: true,
init : function() {
this.on("success", function(file, res){});
//删除图片的事件,当上传的图片为空时,使上传按钮不可用状态
this.on("removedfile", function () {
if (this.getAcceptedFiles().length === 0) {
$("#dropzoneForm").attr("disabled", true);
}
});
}
}; </script> <body> <form action="<%= request.getContextPath()%>/vehicleBasic/upload.do" method="post" enctype="multipart/form-data" class="dropzone" id="dropzoneForm">
</form> </body>
</html>
后台代码:
@RequestMapping("upload")
@ResponseBody
public String upload(@RequestParam(value = "file", required = false) MultipartFile file,
HttpServletRequest request, HttpServletResponse response) throws IOException{
response.setHeader("Access-Control-Allow-Origin","*");
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSS");
String res = sdf.format(new Date());
// uploads文件夹位置
//String rootPath = request.getSession().getServletContext().getRealPath("vehFile");
String rootPath = "ehFile/";
// 原始名称
String originalFileName = file.getOriginalFilename();
// 新文件名
String newFileName = res + originalFileName.substring(originalFileName.lastIndexOf("."));
// 新文件
File newFile = new File(rootPath +File.separator + newFileName);
// 判断目标文件所在目录是否存在
if( !newFile.getParentFile().exists()) {
// 如果目标文件所在的目录不存在,则创建父目录
newFile.getParentFile().mkdirs();
}
System.out.println(newFile);
System.out.println(originalFileName);
// 将内存中的数据写入磁盘
file.transferTo(newFile);
// 完整的url
String fileUrl =rootPath + newFileName;
return fileUrl;
}
DropZone资源路径:
http://download.csdn.net/download/s0009527/10198590
DropZone图片上传控件的使用的更多相关文章
- 百度Ueditor多图片上传控件
发现百度的Ueditor富文本编辑器中的多图片上传控件很不错,于是便想着分享出来使用,费了老劲,少不了无名朋友的帮助,也查了不少资料,终于搞定了 发代码给大家,请大家多多指正 1.首先要在html页面 ...
- java+Word图片上传控件
这种方法是servlet,编写好在web.xml里配置servlet-class和servlet-mapping即可使用 后台(服务端)java服务代码:(上传至ROOT/lqxcPics文件夹下) ...
- uedit富文本编辑器及图片上传控件
微力后台 uedit富文本编辑器及文件上传控件的使用,无时间整理,暂略,参考本地代码.能跑起来.
- Word图片上传控件(WordPaster)更新-2.0.15版本
更新说明: 1. 增加对webp图片的支持,支持微信公众号图片的下载. 效果参考:http://www.ncmem.com/doc/view.aspx?id=9761f8ce4fe04d0ab0f ...
- WebUploader 图片上传控件使用范例
官网 http://fex.baidu.com/webuploader/getting-started.html 其实官网写的挺详细的,看官网也可以了. 引入资源 使用Web Uploader文件上 ...
- bootstrap图片上传控件 fileinput
前端 1.要引用的js fileinput.js fileinput.css <link type="text/css" rel="stylesheet& ...
- 基于jQuery仿uploadify的HTML5图片上传控件jquery.html5uploader
(function($){ var methods = { init:function(options){ return this.each(function(){ var $this = $(thi ...
- Word图片上传控件卸载教程-Xproer.WordPaster
卸载教程: 卸载控件-IE Windows XP Windows 7(x86) Windows 7(x64) 卸载控件-C ...
- Word图片上传控件-eWebEditor9x整合教程-Xproer.WordPaster
示例下载(JSP):eWebEditor9x, 示例下载(.NET):eWebEditor9x, 1.1. 集成到eWebEditor9x 主要步骤如下: 1.增加WordPaster文件夹 ...
随机推荐
- SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID
如题: SDK location not found. Define location with sdk.dir in the local.properties file or with an AND ...
- centos使用--centos7.3配置LNMP
目录 1 源的配置 2 安装软件 2.1 安装php7 2.2 安装nginx 2.3 安装mysql 2.4 安装vsftp (ftp登录配置) 3 开机启动设置 4 其它一些配置 4.1 git的 ...
- python学习笔记二:流程控制
一.if else: #!/usr/bin/python x = int(raw_input('please input:')) if x >= 90: if x >= 95: print ...
- android中dumpsys命令使用
转自:https://testerhome.com/topics/1462 adb shell dumpsys,默认打印出当前系统所有service信息,在后面可加上具体的服务名 需要列出当前运行的服 ...
- C#帮助类
1.集合操作 // <summary> /// 判断一个集合是否包含某个值 /// </summary> /// <typeparam name="T" ...
- 孤荷凌寒自学python第四十一天python的线程同步之Event对象
孤荷凌寒自学python第四十一天python的线程同步之Event对象 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 鉴于Lock锁与RLock锁均宣告没有完全完成同步文件操作的问题,于 ...
- inspect流程
当node节点state为manage时,可执行inspector ironic node-set-provision-state <node_uuid> manage ironic no ...
- pytorch版本问题:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
用pytorch加载训练好的模型的时候遇到了如下的问题: AttributeError: 'module' object has no attribute '_rebuild_tensor_v2' 到 ...
- Hadoop平台K-Means聚类算法分布式实现+MapReduce通俗讲解
Hadoop平台K-Means聚类算法分布式实现+MapReduce通俗讲解 在Hadoop分布式环境下实现K-Means聚类算法的伪代码如下: 输入:参数0--存储样本数据的文本文件inpu ...
- php中变量的详细介绍
变量的含义: 用于存储信息的容器,在程序运行期间,可以变化的量 变量的命名规则: 1.变量以$符开始 2.变量名只能以字母或下划线开始 3.变量名只能是字母,下划线,数字,不能有特殊字符:逗号,句号, ...