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文件夹 ...
随机推荐
- 如何将Windows live writer草稿转存到其他电脑上
ref:http://www.zhengsiwei.com/how-to-draft-windows-live-writer-archived-on-other-computers/ 在写一篇关于 ...
- gettid 和pthread_self的区别
转: Linux中,每个进程有一个pid,类型pid_t,由getpid()取得.Linux下的POSIX线程也有一个id,类型 pthread_t,由pthread_self()取得,该id由线程库 ...
- 剑指Offer - 九度1503 - 二叉搜索树与双向链表
剑指Offer - 九度1503 - 二叉搜索树与双向链表2014-02-05 23:39 题目描述: 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树 ...
- python学习笔记十:异常
一.语法 #!/usr/bin/python filename='hello' #try except finally demo try: open('abc.txt') print hello ex ...
- 图解-Excel的csv格式特殊字符处理方式尝试笔记(个人拙笔)
Excel格式如下.(截图来自,WPS Office) CSV是一种文本格式的Excel文档格式.不支持Excel的字体特效(比如加粗,颜色)等等的保存. 每一行数据用 "\n" ...
- selenium + python之元素定位
selenium对web各元素的操作首先就要先定位元素,定位元素的方法主要有以下几种:通过id定位元素:find_element_by_id("id_vaule")通过name定位 ...
- python学习笔记-基础
1.大小写敏感 2. print (n,f,s1,s2,s3,s4,sep='\n') -- 换行输出 seq='\n' print ('n=%d'%n,'f=%f'%f,'s1=%s'%s1,' ...
- HDU 4681 String 胡搞
设串C的第一个字母在串A中出现的位置是stA, 串C的最后一个字母在串A中出现的位置是edA. 设串C的第一个字母在串B中出现的位置是stB, 串C的最后一个字母在串B中出现的位置是edB. 求出每一 ...
- Linux学习前的准备
Linux学习前的准备 Linux的学习也是这次项目的一个点. 我的学习教材是 The Linux Command Line,这是本已经被翻译好了的 中英版本的教材,知识点还是比较入门的 我使用的是 ...
- 201621123034 《Java程序设计》第7周学习总结
作业07-Java GUI编程 1. 本周学习总结 1.1 思维导图:Java图形界面总结 1.2 可选:使用常规方法总结其他上课内容. 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模 ...