当前位置:编程学习 > JAVA >>

关于uploadify的2.1.4版本

目前在研究jquery的uploadify插件,但是使用过程中,都说2.1.4版本最稳定,可是我写的上传队列无法删除,页面报错

但是相反2.0.1版本却可以,我想问一下 大侠们 这是那的问题
这是jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% 
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
    <base href="<%=basePath%>">
<title>Uploadify</title>
<link href="style/css/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<link href="style/css/uploadify/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="style/viewplugin/jquery/1.4.4/jquery-1.4.4.js"></script>
<script type="text/javascript" src="style/viewplugin/swfobject/swfobject.js"></script>
<script type="text/javascript" src="style/viewplugin/uploadify/jquery.uploadify.v2.1.4.js"></script>
<%-- <script type="text/javascript" src="style/viewplugin/uploadify/jquery.uploadify.v2.0.1.js"></script>--%>
</head>
<body>
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<p>
<!--  -->
<a href="javascript:jQuery('#uploadify').uploadifyUpload()">开始上传</a> 

<a href="javascript:jQuery('#uploadify').uploadifyClearQueue()">取消所有上传</a>
</p>
<script type="text/javascript">
$(document).ready(function() {
$("#uploadify").uploadify({
'uploader'       : '<%=basePath%>style/images/uploadify/uploadify.swf',
'cancelImg'      : '<%=basePath%>style/images/uploadify/cancel.png',
'script'         : 'servlet/Upload?name=frank',
//'script'         : 'upload!doUpload.action',
'folder'         : 'uploads',
'queueID'        : 'fileQueue',
'auto'           : false,
'multi'          : true,
'simUploadLimit' : 2,
'buttonText'  : 'BROWSE'//,
});
});
</script>
</body>
<input style="width:300px" value="<%=path%>"><br/>
<input style="width:300px" value="<%=basePath%>">
</html>


action
package util004_upload;

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;

public class myUploadify extends HttpServlet {

private static final long serialVersionUID = 1L;

@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
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) {
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(".") >= 0) {
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);
}

}
jquery function upload file
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,