Uploading web files may be one of the most common functions in website construction, and I have almost needed to implement file upload function in project development. I got some upload components for some time. This article will be described in this article, and the respective advantages and disadvantages are compared.
First, Smartupload components.
I want to be a friend who is uploaded by the file knows this component, I know the most in the people I know! When I first arrived, the company also used Smartupload, which is a good choice when uploading relatively small files. Here is an example of using:
<% @ page contenttype = "text / html; charset = GB2312"%> <% @ page import = "java.sql. *"%> <% @ Page Import = "com.jspsmart.upload. *"%>
<% // Installing Bean Smartupload Mysmartupload = New SmartUPload (); // Initialization MySmartupload.initialize (PageContext); // Set the maximum value upload, pay attention: If you set up a meeting here! MySmartupload.setMaxFileSize (500 * 1024 * 1024); // Upload file mysmartupload.upload (); // loop acquire all uploaded file for (int i = 0; i
But using SmartupLoad to upload excessive files, or multi-files may have problems with high CPU or memory. And: Only restarting the container to return to normal! This is what I finally gave up using Smartupload. Second, Commons-FileUpload components
This component is the component I am using, downloading address: http://jakarta.apache.org/site/downloads/downloads_commons-fileUpload.cgi, package contains API documentation.
Examples of this component:
<% @ page language = "java" contenttype = "text / html; charSet = GBK"%> <% @ page import = "java.util. *"%> <% @ page import = "org.apache.commons. FileUpload. * "%>
As can be seen from the above program, the component can be used to store temporary files at the time of time, and write the file directly after the completion is completed. This will not take over more memory! And the time is not low when the component is transferred!
In these two comparison options, I chose the latter, because I often upload more than 10m files in the project, when using the former, the server is almost collapsed.
However, I have no need to use these two components, because the HTTP method is always very low, and we now use the web way to implement the FTP file upload. I will write me in the next article how to implement it. of.