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. Unity 好坑的Save Scene

    在编辑一个Untiy工程的时候,有很多的教程提到了 "Save Scene",也知道是干么用的.但是,后面打开工程的时候,工程界面是很多东西都不见了,又忘了有个Save Scene ...

  2. java 基础导航

    ecplise 常用快捷键 java notepad++ java封装好处和原则 java1 基本概述和java环境变量配置 java2 基本概念介绍和基本关键字.基本数据类型 java3 基本流程语 ...

  3. javaSE基础03

    javaSE基础03 生活中常见的进制:十进制(0-9).星期(七进制(0-6)).时间(十二进制(0-11)).二十四进制(0-23) 进制之间的转换: 十进制转为二进制: 将十进制除以2,直到商为 ...

  4. Easyui columns列图片移位问题!!!

    InitGrid: function () { $("#list").datagrid({ toolbar: '#tb', url: BanZhengXiaoLuSearch.Aj ...

  5. Erlang--proplists结构解析

    proplists 模块适用数据量较少的场景,处理配置文件和函数选项时常用.proplists对内部数据结构是Key-Value键值对形式,第一个元素做key用来查询和删除,如果一个key有多个值就会 ...

  6. C#之反射

    Assembly assembly = Assembly.Load("PeopleDal"); //获取程序集名称 Module[] modules = assembly.GetM ...

  7. visual studio 2015连接到MySql相关问题

    vs中使用服务器资源管理器连接到MySQL没有成功.按照网上提供的解决方法,相关插件已经安装: 1.控制面板中,MySQL Connector Net 6.9.9已经安装(原安装版本为6.9.8,后升 ...

  8. 使用Jenkins配置Git和Maven的自动化构建

    Jenkins是一个开源的持续集成工具,应用Jenkins搭建持续集成环境,可以进行自动构建.自动编译和部署,非常方便. 在服务器比较少的情况下,Jenkins的优势并不明显,但是随着项目发展,服务器 ...

  9. 11.Object方法

    综述 Object是Java中所有类的父类,对它的学习十分的重要, Object的函数除了final方法,基本上都是被设计为要被覆盖的(Override),这节我们就一起来学习这些函数. 1.equa ...

  10. .NET 需要处理的高性能WEB架构 - .NET架构

    1.如果不想被微软包围(其实微软的一套并不贵,是被谣言传高了),数据层依然可以选择SQL Server数据库和存储过程. 2.缓存不再依赖.net自身提供的缓存机制,迁移到部署在Linux平台上的分布 ...