API:http://www.uploadify.com/documentation/

下载地址:http://www.uploadify.com/

这几天查看插件,发现uploadify插件做不错,查了一些资料,总结笔记一下。

项目文件截图:

lib如图;

web.xml代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>UploadifyJava</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>UpFileServlet</display-name>
<servlet-name>UpFileServlet</servlet-name>
<servlet-class>com.horizon.action.UpFileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UpFileServlet</servlet-name>
<url-pattern>/UpFileServlet</url-pattern>
</servlet-mapping>
</web-app>

UpFileServlet.java代码:

package com.horizon.action;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.UUID; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 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; /**
* Servlet implementation class UpFileServlet
*/
public class UpFileServlet extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public UpFileServlet() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 获得参数
String timestamp = request.getParameter("timestamp");
String token = request.getParameter("token");
System.out.println(timestamp);
System.out.println(token);
// 获得文件
String savePath = this.getServletConfig().getServletContext()
.getRealPath("");
savePath = savePath + "/uploads/";
File f1 = new File(savePath); System.out.println(savePath); if (!f1.exists()) {
f1.mkdirs();
}
DiskFileItemFactory fac = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fac);
upload.setHeaderEncoding("utf-8");
List fileList = null;
try {
fileList = upload.parseRequest(request);
} catch (FileUploadException ex) {
System.out.println(ex.getMessage());
return;
} Iterator<FileItem> it = fileList.iterator();
String name = "";
String extName = "";
while (it.hasNext()) {
FileItem item = it.next();
if (!item.isFormField()) {
name = item.getName();
long size = item.getSize();
String type = item.getContentType();
System.out.println(size + " " + type);
if (name == null || name.trim().equals("")) {
continue;
} // 扩展名格式:
if (name.lastIndexOf(".") >= ) {
extName = name.substring(name.lastIndexOf("."));
} File file = null;
do {
// 生成文件名:
name = UUID.randomUUID().toString();
file = new File(savePath + name + extName);
} while (file.exists());
File saveFile = new File(savePath + name + extName);
try {
item.write(saveFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
response.getWriter().print(name + extName);
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
} }

index.jsp代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>UploadiFive Test</title>
<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="js/uploadify/jquery.uploadify.min.js"
type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="js/uploadify/uploadify.css">
<style type="text/css">
body {
font: 13px Arial, Helvetica, Sans-serif;
}
</style>
</head>
<body>
<h1>Uploadify Demo for java</h1>
<form>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true" />
<a href="javascript:$('#file_upload').uploadify('upload')">开始上传</a>&nbsp;
<a href="javascript:$('#file_upload').uploadify('cancel')">取消所有上传</a>
</p>
</form>
<script type="text/javascript">
$(function() {
var timestamp = new Date().getTime();
$('#file_upload').uploadify({
'formData' : {
'timestamp' : timestamp,
'token' : 'unique_salt' + timestamp
},// 设置想后台传递的参数 如果设置该参数,那么method应该设置为get,才能得到参数
'swf' : 'js/uploadify/uploadify.swf',// 指定swf文件
'uploader' : 'UpFileServlet',// 后台处理的页面
'cancelImg' : 'js/uploadify/uploadify-cancel.png',// 取消按钮图片路径
"queueID" : 'queue',// 上传文件页面中,你想要用来作为文件队列的元素的id, 默认为false 自动生成, 不带#
'method' : 'get',// 设置上传格式
'auto' : false,// 当选中文件后是否自动提交
'multi' : true,// 是否支持多个文件上传
'simUploadLimit' : ,
'buttonText' : '选择文件',// 按钮显示的文字
'onUploadSuccess': function (file, data, response) {// 上传成功后执行
$('#' + file.id).find('.data').html(' 上传完毕');
}
});
});
</script>
</body>
</html>

期间在上传参数时,发现无法传送,经过查CSDN的资料,可以设置method参数为get,来解决问题。

针对,上传是complete转为中文,jquery.uploadify.js源码下图:

得出结论。

参考网址:http://www.cnblogs.com/babycool/archive/2012/08/04/2623137.html

另外还有html5版本,需要的话可以查看官网

uploadify的java应用的更多相关文章

  1. Struts2+Uploadify文件上传使用详解

    Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.不过官方提供的实例是php版本的,本文将详细介绍Uploadify在java中的使用,您也可以点击下面的链接进行演示或下 ...

  2. Struts2 + uploadify 多文件上传完整的例子!

    首先,我这里使用的是  Jquery  Uploadify3.2版本号  导入相关的CSS  JS    <link rel="stylesheet" type=" ...

  3. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  4. uploadify前台上传文件,java后台处理的例子

    1.先创建一个简单的web项目upload (如图1-1) 2.插件的准备 (1).去uploadify的官网下载一个uploadify插件,然后解压新建个js文件夹放进去(这个不强求,只要路径对了就 ...

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

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

  6. java应用uploadify 3.2丢失session

    java应用uploadify 3.2丢失session http://c-bai.iteye.com/blog/1829269 uploadify上传用的是一个flash插件. flash中有个bu ...

  7. java版-JQuery上传插件Uploadify使用实例

    摘自:http://itindex.net/detail/47160-java-jquery-%E4%B8%8A%E4%BC%A0 运行效果: 包结构图: 后台JAVA逻辑: package com. ...

  8. java 上传2(使用java组件fileupload和uploadify)

    项目关键包和插件

  9. uploadify 3.2 java应用丢失session

    flash中有个bug就是自身创建一个session,这样就导致与web本身的session不一致 权限验证失败的问题.  原因: 因为uploadify是不会自动传送session值的,所以当ses ...

随机推荐

  1. [xsy2913]enos

    题意:一棵树,点有$0,1,2$三种颜色,支持路径修改颜色和查询点所在同色连通块的大小 lcm太可怕了,于是去问了sk,得到一个优质做法 考虑lct维护子树信息,$vs_{x,i}$为$x$的虚儿子中 ...

  2. C#高级编程9-第4章 继承

    继承是面向对象的一大特征.要深刻学习继承,需要学会使用调试的技巧来学习它,因为它比较抽象. 继承 继承是指一个具体的类型直接使用另一类型的某些数据成员或函数成员,继承的类是基类(父类),被继承的类是派 ...

  3. AppDelegate 方法介绍

    // //  AppDelegate.swift //  SwifyDemo import UIKit import CoreData @UIApplicationMain // 入口函数 UIApp ...

  4. org.springframework.orm.hibernate3.LocalSessionFactoryBean

    Spring整合hibernate在配置sessionFactory时, 启动总是报出javax.transaction.TransactionManager找不到. 原因是:缺少jar包,jta-1 ...

  5. HK设备安全补丁升级方案

    1.背景:          当前很多HK行业设备的端口映射到公网上,其中一部分老版本设备是存在安全漏洞的,由于传统行业没有设备平台的概念,无法通过设备提示用户进行升级,导致这些存在漏洞的设备在互联网 ...

  6. c# 四舍五入、上取整、下取整

    在处理一些数据时,我们希望能用“四舍五入”法实现,但是C#采用的是“四舍六入五成双”的方法,如下面的例子,就是用“四舍六入五成双”得到的结果: double d1 = Math.Round(1.25, ...

  7. Material Design(原质化设计)视觉设计语言规范 踏得网镜像

    Android 5.0 Lollipop(棒棒糖,也就是之前的代称Android L)全面实践了谷歌最新研发的 Material Design 设计语言规范,只是该设计规范并不是仅针对移动平台. 我们 ...

  8. 26复杂类型比较,使用Compare .NET objects组件

    关于比较对象,在"06判等对象是否相等"中大致可以总结为:   关于比较方法: ● 实例方法Equals(object obj)既可以比较值类型,也可以比较引用类型 ● 静态方法E ...

  9. MySQL数据库事务各隔离级别加锁情况--read committed && MVCC(转)

    本文转自https://m.imooc.com/article/details?article_id=17290 感谢作者 上篇记录了我对MySQL 事务 隔离级别read uncommitted的理 ...

  10. 分析oracle索引空间使用情况,以及索引是否须要重建

    分析索引空间使用情况.以及索引是否须要重建 分析其它用户下的索引须要 analyze any的权限 分析索引前先查看表的大小和索引的大小,假设索引大小和表大小一样大或者大于表的大小,那么能够推断索引可 ...