Java's documentation has always been a matter of attention, and there are several NBs provide this feature. The most considered three (I know these three), one is more early JSPSMARTupload, The other is the comMonupload from the family, and one is ORELLY. I have more than two, the total feeling is that JSPSmartup is more flexible, function is stronger (a little bit), but now online No maintenance, no download, especially when it uploads, put the upload file in memory, so the size of the upload file is related to the memory. Commonupload does not provide a lot of API, but it has a relatively flexible process. The uploaded file is written first, so the uploaded size is just a relationship. I tried the biggest upload file size of 700m, of course, it is local test:> Is it in Linux / UNIX system upload files Question, I have some solved in the code below.
Below is the upload code of the first two ways:
Try {// Take the session user oidint pid = userinfo.getUserid (); string sys_user_id = string.valueof (pid); // Take the parameter value of the init configuration file string sitephysicalPath = (STRING) init.getObject ("SitephysicalPath"); String Savedir = (String) Init.getObject ("InfoupLoadDir"); String Tempdir = (String) Init.getObject ("InfoupLoadDir"); String FileMEMO = ""; // File Description String FileName = NULL; // Store to Database File name string savename = null; // Store the local file name string filepath = null; // Store SAVEPATH = null; // Stores LONG FILESIZE = 0; // File Size INT MAXPOSTSIZE = -1; INT DINFO_UPLOAD_ID = -1;%> <% // Initialization MySmartupload.initialize (PageContext); // Upload file mysmartupload.upload (); // Loop acquire all upload file for (INT i = 0 i } Catch (Exception E) {Savename = "";} // acquired file size filesize = file.getsize (); // Storage path string sql_id = "select s_info_upload.nextVal as seqid from dual"; try {statement stmt = con .createStatement (); ResultSet rst = stmt.executeQuery (sql_id); while (rst.next ()) {dinfo_upload_id = rst.getInt ( "seqid");}} catch (SQLException sqle) {return;} filePath = sitePhysicalPath saveDir Integer.toString (dinfo_upload_id) saveName; savePath = saveDir Integer.toString (dinfo_upload_id) saveName; // file to the local storage file.saveAs (filePath); // file stored in a database switch (i) {case 0 : FileMemo = (String) mysmartupload.getRequest (). getParameter ("Memo1"); Break; Case 1: FileMemo = (String) mysmartupload.getRequest (). getParameter ("Memo2"); break; case 2: filememo = String) mySmartUpload.getRequest () getParameter ( "memo3"); break; case 3:. fileMemo = (String) mySmartUpload.getRequest () getParameter ( "memo4"); break; case 4:. fileMemo = (String) mySmartUpload. getRequest (). getParameter ("Memo5"); Break; Default: FileMemo = "" String sql = "INSERT INTO info_upload (info_upload_id, sys_user_id, file_size, file_path, utime, deleted)" "VALUES (" Integer.toString (dinfo_upload_id) "," sys_user_id "," fileSize ", '" SavePath "', sysdate, 0)"; SQLCMD CMD = New SQLCMD (Con, SQL); // System.out.Println (SQL); java.sql.preparedState pstmt = null; java.sql.Statement Stmt = null; // fileName = fileName.substring (0, fileName.indexOf () "."); String sql_cn = "UPDATE info_upload SET file_name = ?, file_memo = WHERE info_upload_id =??"; java.io.ByteArrayInputStream bais_name = new java.io.ByteArrayInputStream (fileName.getBytes ( "ISO-8859-1")); java.io.InputStreamReader isr_name = new java.io.InputStreamReader ((InputStream) bais_name, "GBK"); java.io.ByteArrayInputStream bais_memo = new java.io.ByteArrayInputStream (fileMemo.getBytes ( "GBK")); java.io.InputStreamReader isr_memo = new java.io.InputStreamReader ((InputStream) bais_memo, "GBK"); try {stmt = con.createStatement ( ); stmt.getConnection (). setAutocommit (false); pstmt = con.prepareStatement (sql_cn); pstmt.setCharacterStream (1, isr_name, fileName.length ()); pstmt.setCharacterStream (2, isr_memo, fileMemo.length ()); pstmt.setInt (3, dinfo_upload_id); //System.out.println (SQL_CN); Pstmt.execute (); stmt.executeUpdate ("commit"); } catCH (Exception Exce) {system.ord.Println (Exce); stmt.executeUpdate ("rollback");}}}} catch (Exception E) {} The above is a JSPSMART, if you want other ways, please download all source code. JSPSMARTUPLOAD download now is now available, if you don't have this package, you can download it on this site. click to download If you have any questions, please contact me: Webmaster@bcxy.com All source code and related document downloads: http://www.bcxy.com/java/javaupload.htm