<%@page import="org.apache.tomcat.jni.File"%> <%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*" import="com.test.util.*"%> <%@ taglib uri="my-taglib" prefix="myTag"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "https://www.jb51.net/"; int SHOW_CONTROL = 0; final String RECORED_PATH = "c:\\a.txt"; String getParameter = request.getParameter("num"); if(getParameter !=null){ System.out.println("getParameter "+getParameter); SHOW_CONTROL = Integer.parseInt(getParameter); }else{ SHOW_CONTROL = 0; } List data = new ArrayList(); String data1[] = new String[]{"相片","代工紙","其他","報價單","圖則"}; int data2[] = new FileUtil().getAllFileSize(data1); for(int i = 0;i<data1.length;i++){ data.add(new String[]{data1[i],data2[i]+"","",""}); } List files = new ArrayList(); List<String> fileList = new FileUtil().readTxtFileByPath(RECORED_PATH,data1[SHOW_CONTROL]); int FILE_SIZE = fileList.size(); int fileID[] = new int[FILE_SIZE]; String fileName[] = new String[FILE_SIZE]; String fileDate[] = new String[FILE_SIZE]; String fileRemark[] = new String[FILE_SIZE]; for(int i=0;i<FILE_SIZE;i++){ Map<String,String> map =new FileStringUtil().getFileDetails(fileList.get(i)); fileID[i] = i+1; fileName[i] = map.get("fileDetail0"); fileDate[i] = map.get("fileDetail1"); fileRemark[i] = map.get("fileDetail2"); files.add(new String[]{fileID[i]+"",fileName[i],fileDate[i],fileRemark[i],""}); } request.setAttribute("data" ,data); request.setAttribute("files" ,files); %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.jb51.net/<%=basePath%>" > <title>Upload</title> <!--装载文件--> <link href="https://www.jb51.net/css/uploadify.css" type="text/css" /> <link href="https://www.jb51.net/css/Regist.css" type="text/css" /> <link href="https://www.jb51.net/css/jquery.ui.all.css"> <script type="text/javascript" src="https://www.jb51.net/uploadify/jquery-1.9.1.js"></script> <script type="text/javascript" src="https://www.jb51.net/uploadify/jquery.uploadify.min.js"></script> <!--ready事件--> <script type="text/javascript"> $(document).ready(function() { $("#uploadify").uploadify({ 'method':'get', 'uploader' : 'servlet/Upload', 'swf' : 'uploadify/uploadify.swf', 'cancelImg' : 'https://www.jb51.net/img/uploadify-cancel.png', 'folder' : 'uploads',//您想将文件保存到的路径 'queueID' : 'fileQueue',//与下面的id对应 'queueSizeLimit' : 5, 'fileDesc' : 'rar文件或zip文件', 'fileExt' : '*.rar;*.zip', //控制可上传文件的扩展名,启用本项时需同时声明fileDesc 'auto' : false, 'multi' : false, 'uploadLimit' : 10, 'buttonText' : '選擇檔案', 'removeCompleted':false, onUploadStart: function(file) { $('#uploadify').uploadify( 'settings', 'formData', { 'save_path': escape(document.getElementById("save_type_select").options[document.getElementById("save_type_select").selectedIndex].value), 'remark':escape(document.getElementById("remark").value) });} , onUploadSuccess: function (file, data, response) { window.location.reload(); } }); }); function ReStartJSP(num){ location.replace("http://localhost:8080/uploadifyTest/index.jsp?num="+num); } function onload(){ initOptions(); ReadTxtFile(); } function initOptions(){ // alert(isNaN(parseInt(size))); var num = <%=data1.length%>; for(var i = 0;i<num;i++){ var optionText = document.getElementById("hidden_"+i).value; document.getElementById("save_type_select").add(new Option(optionText,optionText)); } } function setOptions(obj){ var SelectObj = document.getElementById("save_type_select"); SelectObj.options[parseInt(obj.value)].selected = true; } function showDIV(obj){ var div = document.getElementById("fileUploadDIV"); if(div.style.display == "none"){ div.style.display = "block"; } setOptions(obj); } function hindDIV(){ var div = document.getElementById("fileUploadDIV"); if(div.style.display == "block"){ div.style.display = "none"; } } function deleteFile(name){ var showMessage = "c:\\"+"<%=data1[SHOW_CONTROL]%>"+"\\"+name; var fso = new ActiveXObject("Scripting.FileSystemObject"); if(fso.FileExists(showMessage)){ fso.DeleteFile(showMessage); alert("delete success!!"); location.replace("http://localhost:8080/uploadifyTest/index.jsp?num="+<%=SHOW_CONTROL%>); } } </script> </head> <body> <myTag:iter columnSize="4" files="${files}" data="${data}" /> </br></br></br> <div> <table > <tr> <td><select></select></td> <td><input type="file"/> </td> <td><label>備註:</label ><input type="text" value='maah%e4u5848在哪呢你5874'/></td> <td><a href="javascript:$('#uploadify').uploadify('upload');">上載</a></td> <td><a href="javascript:$('#uploadify').uploadify('cancel'); hindDIV()">取消</a></td> </tr> </table> <div ></div> </div> </body> </html>
至此,这个小项目就写到这里,下面是Demo连接