js:

$("#uploadify").uploadify({
'uploader':'uploadServlet',
'swf':'image/uploadify.swf',
'cancelImg' : 'image/uploadify-cancel.png',
'folder' : 'upload/full', //您想将文件保存到的路径
'queueID' : 'fileQueue',//与下面的id对应
'queueSizeLimit' : 5,
'fileSizeLimit' : '2MB',
'fileTypeDesc' : 'jpg文件或png文件',
'fileTypeExts' : '*.jpg;*.png', //控制可上传文件的扩展名,启用本项时需同时声明fileDesc
'auto' : false,
'multi' : true,
'simUploadLimit' : 2,
'buttonText' : '选择文件',
'onUploadSuccess':function(file,data,response){
console.log(data);
$("#picList").append(data);
}
});

  

后台servlet:

package com.lab.util;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Iterator;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.log4j.Logger; import com.lab.po.ClientPO;
import com.lab.po.IbeaconPO;
import com.lab.po.PicturePO;
import com.lab.service.ClientService;
import com.lab.service.PictureService;
import com.lab.service.impl.PictureServiceImpl; /**
* Servlet implementation class uploadServlet
*/
public class uploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(uploadServlet.class);
/**
* @see HttpServlet#HttpServlet()
*/
public uploadServlet() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8"); DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload sfUpload = new ServletFileUpload(factory);
sfUpload.setFileSizeMax(5000*1024); boolean flag = false;
String fileName = null;
ServletContext svct = getServletContext();
String path=svct.getRealPath("upload");
System.out.println(path); try {
List<FileItem> list = sfUpload.parseRequest(request);
Iterator<FileItem> items = list.iterator();
while(items.hasNext()){
FileItem item = items.next();
if(!item.isFormField()){ fileName = item.getName();
System.out.println(fileName); fileName = System.currentTimeMillis()+fileName.substring(fileName.lastIndexOf("."));
String uploadDir = path+"\\full\\"+fileName;
File file = new File(path);
if(!file.exists()){
file.mkdir();
}
File ffile = new File(uploadDir);
if(!ffile.exists()){
item.write(ffile);
flag=true;
} }
} } catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(flag){
String fullPath=path+"\\full\\"+fileName;
String thumbPath=path+"\\thumb\\"+fileName;
PictureUtil.toThumbPic(fullPath, thumbPath);
PicturePO picturePO = new PicturePO();
picturePO.setFull_path("upload\\full\\"+fileName);
picturePO.setThumb_path("upload\\thumb\\"+fileName);
HttpSession session = request.getSession(false);
if(session!=null){
picturePO.setIbeaconPO((IbeaconPO)session.getAttribute("ibeacon"));
}
//调用service方法时,只能通过getbean的方法得到service实例,普通的@resource不能用。
PictureService pictureService=(PictureService) AppContext.getInstance().getAbstractApplicationContext().getBean("pictureService"); //PictureService pictureService = new PictureServiceImpl();
System.out.println(picturePO.getId());
String resultString=null;
if(pictureService.addPicture(picturePO)){
if(session.getAttribute("client")!=null){
ClientPO clientPO = (ClientPO) session.getAttribute("client");
clientPO.setUpdateDate(new Date());
ClientService clientService = (ClientService) AppContext.getInstance().getAbstractApplicationContext().getBean("clientService");
clientService.updateClient(clientPO);
}
logger.info("上传图片成功!");
System.out.println(picturePO.getId());
resultString = "<li><div class='myCheckbox'><input type='checkbox' name='picCheck' value='"+picturePO.getId()+"' /></div><img onclick='showFullPic("+picturePO.getId()+")' src='"+picturePO.getThumb_path()+"' class='img-thumbnail'><br/><span><button type='button' class='btn btn-default btn-sm' onclick='deletePic("+picturePO.getId()+",this)'>删除</button></span></li>";
}else{
resultString = "false";
} response.getWriter().print(resultString);
//out.println("<script>parent.callBack('"+fileName+"')</script>");
}else{
//out.println("<script>parent.callBack('upload failed')</script>");
}
} }

  

uploadify批量上传的更多相关文章

  1. mvc中使用uploadify批量上传的应用

    网上找了很多资料都没有发现一个好用.可以用的uploadify批量上传的应用,这里通过官方和自己的一些项目需要整理了一个出来. 希望能帮助到需要的人. 效果图:

  2. Yii Uploadify批量上传

    控制器: $reinfo = "fail"; $filename=""; //重要说明: //使用uploadify 上传时,每次这个sessionID都会改变 ...

  3. uploadify+批量上传文件+java

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  4. 完整uploadify批量上传文件插件使用

    1.首先准备uploadify的js文件,网上一搜一大堆 2.上传页面UpFilePage.aspx 关键代码: <html xmlns="http://www.w3.org/1999 ...

  5. 带进度条的文件批量上传插件uploadify

    有时项目中需要一个文件批量上传功能时,个人认为uploadify是快速简便的解决方案. 先上效果图: 一. 下载uploadify 从官网下载uploadify的Flash版本(Flash版本免费,另 ...

  6. 利用uploadify+asp.net 实现大文件批量上传。

    前言 现在网上文件上传组件随便一搜都是一大堆,不过看大家一般都在用uploadify这个来上传文件.由于项目需要,我在来试了一下.因为第一次使用,也遇到了很多问题,特此记录! ------------ ...

  7. uploadify文件批量上传

    uploadify能够时间文件的批量上传,JS文件包下载地址,使用说明可以参考官网文档(http://www.uploadify.com/documentation/) 使用方法如下代码: $(&qu ...

  8. Springmvc+uploadify实现文件带进度条批量上传

    网上看了很多关于文件上传的帖子,众口不一,感觉有点乱,最近正好公司的项目里用到JQuery的uploadify控件做文件上传,所以整理下头绪,搞篇文档出来,供亲们分享. Uploadify控件的主要优 ...

  9. MVC批量上传文件(使用uploadify)

    <script src="JS/jquery-1.8.3.js"></script> <script src="uploadify/jque ...

随机推荐

  1. JAVA基础学习——1.2 环境搭建 之eclipse安装及中文化

    安装好jdk,配置好环境变量以后,下面就可以进行安装eclipse了. 闲话少说,eclipse下载地址:http://www.eclipse.org/downloads/ 不大用关注checksum ...

  2. Cordova环境搭建 & HelloWorld

    目前的手机APP有三类:原生APP,WebAPP,HybridApp:HybridApp结合了前两类APP各自的优点,越来越流行. Cordova就是一个中间件,让我们把WebAPP打包成Hybrid ...

  3. CentOS7下安装配置MariaDB

    参考: http://www.2cto.com/os/201504/394141.html http://outofmemory.cn/code-snippet/2533/mysql-create-d ...

  4. Js/Jquery获取iframe中的元素

    转载: Js/Jquery获取iframe中的元素 - - ITeye技术网站http://java-my-life.iteye.com/blog/1275205 在web开发中,经常会用到ifram ...

  5. 关于chart.js 设置canvas的宽度为父级元素的宽度的百分百 以及 X轴上面刻度数据太多如何处理

    今天在做一个数据统计的界面的时候,需要做折线统计图,在网上找了一圈发现数据统计的插件还是不少的,本着轻量级的的原则选择了Chart.js,后来在做的过程中便遇到两个问题,以此记录下来,和刚刚接触前端的 ...

  6. cornerstone知识点

    CornerStone使用教程(配置SVN,HTTP及svn简单使用) 发布时间:2015-01-02 19:54   作者:芳仔小脚印    来源:开源中国 CornerStone是Mac OS X ...

  7. 文件服务器:FTP服务器详解

    文件服务器:FTP服务器 数据传输原理 功能简介 文件的传输与管理 不同等级的用户身份:user.guest.anonymous 实体用户.权限较完整 匿名用户.下载资源的能力 命令记录与日志文件记录 ...

  8. iOS推送小结(证书的生成、客户端的开发、服务端的开发)

    1.推送过程简介 1.1.App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远程推送的申请 ...

  9. Sublime Text实用小技巧

    1.输入"!"或"html:5",然后按Tab键: html:5 或!:用于HTML5文档类型 html:xt:用于XHTML过渡文档类型 html:4s:用于 ...

  10. STL string的构造函数

    前几天在网上,一位网友问我几个问题如下: , 'A'); string S1 = "abcdefg"; , ); ); cout << "s0 = " ...