项目截图:
index.jsp 代码--》 down的例子做的修改(不知道哪里改错了的)
01 | < link rel = "stylesheet" type = "text/css" href = "css/uploadify.css" > |
02 | < script type = "text/javascript" src = "jquery/jquery.uploadify.min.js" ></ script > |
03 | < script type = "text/javascript" src = "jquery/jquery-1.7.js" ></ script > |
04 | < script type = "text/javascript" src = "jquery/swfobject2.2.js" ></ script > |
06 | $(document).ready(function() { |
07 | $("#uploadify").uploadify({ |
13 | 'successTimeout':99999, |
20 | 'swf': "jquery/uploadify.swf", |
21 | 'queueID':'fileQueue', |
22 | 'fileObjName':'"uploadify"', |
23 | 'uploader':'uploadAction', |
24 | 'buttonImage':'jquery/uploadify-cancel.png', |
27 | 'fileTypeDesc':'支持的格式:', |
28 | 'fileSizeLimit':'10000MB', |
29 | 'buttonText' : '选择文件',//浏览按钮 |
30 | 'queueSizeLimit' : 25, |
32 | 'onUploadProgress' : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) { |
33 | //有时候上传进度什么想自己个性化控制,可以利用这个方法 |
37 | 'onSelect' : function(file) { |
40 | 'onSelectError':function(file, errorCode, errorMsg){ |
43 | alert("上传的文件数量已经超出系统限制的"+$('#uploadify').uploadify('settings','queueSizeLimit')+"个文件!"); |
46 | alert("文件 ["+file.name+"] 大小超出系统限制的"+$('#uploadify').uploadify('settings','fileSizeLimit')+"大小!"); |
49 | alert("文件 ["+file.name+"] 大小异常!"); |
52 | alert("文件 ["+file.name+"] 类型不正确!"); |
57 | 'onFallback':function(){ |
58 | alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。"); |
60 | //上传到服务器,服务器返回相应信息到data里 |
61 | 'onUploadSuccess':function(file, data, response){ |
62 | //$('#uploadify').uploadify('upload'); |
75 | < div id = "fileQueue" style = "width:300px" ></ div > |
76 | < input type = "file" name = "uploadify" id = "uploadify" multiple = "true" /> |
78 | < a href = "javascript:$('#uploadify').uploadify('upload')" >开始上传</ a > |
79 | < a href = "javascript:$('#uploadify').uploadify('cancel')" >取消所有上传</ a > |
处理action代码:
01 | @SuppressWarnings ( "serial" ) |
02 | public class UploadAction extends ActionSupport { |
04 | private File uploadify; |
07 | private String uploadifyFileName; |
10 | @SuppressWarnings ( "deprecation" ) |
11 | public String uploadFile() throws Exception { |
17 | String newFileName = "" ; |
20 | String nowTime = new SimpleDateFormat( "yyyymmddHHmmss" ) |
24 | String savePath = ServletActionContext.getRequest().getRealPath( "" ); |
27 | savePath = savePath + "/uploads/" ; |
28 | System.out.println(savePath); |
29 | HttpServletResponse response = ServletActionContext.getResponse(); |
30 | response.setCharacterEncoding( "utf-8" ); |
34 | if (uploadifyFileName.lastIndexOf( "." ) >= 0 ) { |
35 | extName = uploadifyFileName.substring(uploadifyFileName |
38 | newFileName = nowTime + extName; |
41 | uploadify.renameTo( new File(savePath + newFileName)); |
44 | response.getWriter().print(uploadifyFileName + "上传成功" ); |
53 | public File getUploadify() { |
58 | public void setUploadify(File uploadify) { |
59 | this .uploadify = uploadify; |
63 | public String getUploadifyFileName() { |
64 | return uploadifyFileName; |
68 | public void setUploadifyFileName(String uploadifyFileName) { |
69 | this .uploadifyFileName = uploadifyFileName; |