1. Download the Uploadify Zip Package. It’s FREE!
2. Unzip the package and upload the following files into a folder on your website:
3.submit.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
Insert title here
测试多文件上传
4.\web\control\Admin2LoginController.java
@RequestMapping(params = "method=OOKK", method = RequestMethod.POST)
public String OOKK(HttpServletRequest request) throws Exception {
String navTabid = request.getParameter("navTabid");
String opeatorId = request.getParameter("opeatorId");
//注意这里上传2个文件,这里会被调用两次;
//这里应该是真正上传文件保存到数据库的过程
String firstParam="返回参数1";
String secondParam="返回参数2";
List list = new ArrayList();
list.add("郭小心");
list.add("王晓霞");
request.setAttribute("mylist", list);
request.setAttribute("statusCode", "200");
request.setAttribute("message", getJason(firstParam,secondParam,list));
request.setAttribute("callbackType", "");
request.setAttribute("navTabId", "");
System.out.println("哥真上传了!哥还返给你个串:"+getJason(firstParam,secondParam,list));
return "admin2/security/ajaxDone";
}
private String getJason(String fParam,String sParam,List list) {
int sum = list.size();
String jason1 = "{firstParam:'"+fParam+"',secondParam:'"+sParam+"',totalProperty:" + sum + ",root:[";
String jason2 = "";
String jason3 = "]}";
StringBuffer jason = new StringBuffer(200);
Iterator iterator = list.iterator();
int i = 0;
while (iterator.hasNext()) {
String u = (String) iterator.next();
jason.append("{id:'" + i++
+ "',value:'"+u+"'},");
}
jason2 = jason.toString();
if (jason2.equals("")) {
return jason1 + jason2 + jason3;
}
return jason1 + jason2.substring(0, jason2.length() - 1) + jason3;
}
哥真上传了!哥还返给你个串:{firstParam:'返回参数1',secondParam:'返回参数2',totalProperty:2,root:[{id:'0',value:'郭小心'},{id:'1',value:'王晓霞'}]}
系统返回JSON 的串是这样的:
=============================================================================================================
参考文档:
uploaderOption: http://www.uploadify.com/documentation/
auto : true, // Automatically upload files when added to the queue
buttonClass : '', // A class name to add to the browse button DOM object
buttonCursor : 'hand', // The cursor to use with the browse button
buttonImage : null, // (String or null) The path to an image to use for the Flash browse button if not using CSS to style the button
buttonText : 'SELECT FILES', // The text to use for the browse button
checkExisting : false, // The path to a server-side script that checks for existing files on the server
debug : false, // Turn on swfUpload debugging mode
fileObjName : 'Filedata', // The name of the file object to use in your server-side script
fileSizeLimit : 0, // The maximum size of an uploadable file in KB (Accepts units B KB MB GB if string, 0 for no limit)
fileTypeDesc : 'All Files', // The description for file types in the browse dialog
fileTypeExts : '*.*', // Allowed extensions in the browse dialog (server-side validation should also be used)
height : 30, // The height of the browse button
itemTemplate : false, // The template for the file item in the queue
method : 'post', // The method to use when sending files to the server-side upload script
multi : true, // Allow multiple file selection in the browse dialog
formData : {}, // An object with additional data to send to the server-side upload script with every file upload
preventCaching : true, // Adds a random value to the Flash URL to prevent caching of it (conflicts with existing parameters)
progressData : 'percentage', // ('percentage' or 'speed') Data to show in the queue item during a file upload
queueID : false, // The ID of the DOM object to use as a file queue (without the #)
queueSizeLimit : 999, // The maximum number of files that can be in the queue at one time
removeCompleted : true, // Remove queue items from the queue when they are done uploading
removeTimeout : 3, // The delay in seconds before removing a queue item if removeCompleted is set to true
requeueErrors : false, // Keep errored files in the queue and keep trying to upload them
successTimeout : 30, // The number of seconds to wait for Flash to detect the server's response after the file has finished uploading
uploadLimit : 0, // The maximum number of files you can upload
width : 120, // The width of the browse button