I read ahxu's article about the progress of uploading files and understood the principle. Because ahxu is not open-source, I had to write it myself for future extension, otherwise, I will not re-invent the wheel.
First of all, go to the Apache official website under the latest commons-fileupload-1.1.1.jar and its source code, looked at it, found some discrepancies with the original version, carefully looked at the source code of the commons-fileupload-1.1.1, understand its entire process, in inputstream, you can get the progress. Here, I want to thank ahxu for his contribution.
OK, start to the topic. In the new version, we use servletfileupload, read the source code, write a class similar to it, and just overwrite the parserequest method, and attach some methods from ahxu's brother.
When writing code, you also need to use the servlet package servlet-api.jar.
When debugging is completed, the following error occurs: Java. lang. noclassdeffounderror: ORG/Apache/commons/IO/output/deferredfileoutputstream, then a query to know the less commons-io-1.2.jar, plus, it is OK.
On the acquisition and display progress, I used a self-written Ajax application architecture, extracted part of the code from it, note that JS files only apply to the UTF-8 coding page, because now I only write UTF-8 coding page, International convenience.
The following is an example.
The source code is provided below:
Process uploaded files
Example
Progressupload. jar contains the commons-fileupload-1.1.1.jar, servlet-api.jar, commons-io-1.2.jar, in progressupload. jar, it also contains an attribute file that contains some default configurations that can be modified as needed.
Because of the source code, you can view the source code on your own. In addition, I wrote it in that example. I will not go into details here. In this example, only fileitem is obtained, and then the item is saved. The sample code is as follows:
File upfile = new file (remotefilepath );
Try
{
Item. Write (upfile );
Fileinfo. Put ("infotip", "uploaded successfully .");
}
Catch (Java. Lang. Exception E)
{
Fileinfo. Put ("infotip", "Upload Failed .");
}
If you have any new ideas, please leave a message to me. It is the best principle to make this thing a good job and develop it together.