First, study case: By filling out the form on the uploadfile.jsp page, jump to the success.jsp page after submission, and then verify the upload the upload file under the package is successful.
Second, case analysis:struts2file upload is not a superficial view of the file can be uploaded simply by simple configuration. is actually divided into two steps. 1,struts2First, save the file uploaded by the client toStruts.multipart.saveDirif the directory that corresponds to the key does not exist, it will be saved to theJavax.servlet.context.tempdirThe directory specified by the environment variable. 2,Actionas defined in theFilemember variables of typefileis actually pointing to temporary files in the temp directory, and then the server side passesIOwrites temporary files to the specified server-side directory.
A) first on the upload page (uploadfile.jsp definition form)
1, Form label method is post, add enctype="Multipart/form-data"
2. The name of the input tag of type file is defined in the action We define it as "file" .
b) Create action(uploadfileaction.java)
1. Upload a file We need three member variables first:
Private File file ;
Private String Filefilename ;
Private String Filecontenttype ;
2, file name to obtain the provisions: file name +filename
3. File type Get provisions: File name +contenttype
4, through the IO operation file Upload.
c) configuration struts.xml
D) The Create Success page (success.jsp) Displays the file name and type.
e) struts2 file Upload principle Analysis
1, after the completion of the project upload, we can find out by viewing the console output:
Info: Unable to find ' struts.multipart.saveDir ' property setting. Defaulting to Javax.servlet.context.tempdir
from the previous chapter " Struts2 's default.properties detailed "in understanding, Configuration Struts.multipart.saveDir can be.
2. We can view the temporary file by outputting the temporary file path in the program
3, the file upload after successful deletion, so we can in the program to let the thread sleep view temporary files.
f) If you want to know more file upload, you can Baidu, very simple, not much explanation here.
Third, Experience:
A) through the previous "Struts2 Servlet File upload detailed" blog post, we learn struts2 The file upload is not as easy to understand. Analysis down, in fact, struts2 is just the bottom of the package, let us use more convenient.
b) in the above F is not explained, because we use multi-file upload in the project, generally do not implement their own, about multi-file upload we generally use plug-ins. In my website "Partner of Love", the photo upload in the album is the plugin used.
c) on the multi-file upload plugin, if you like can Baidu, really can't do, can communicate with me, help everyone realize.
Iv. Reference Project: http://download.csdn.net/detail/u011638419/8218863
Five, a day of joy:
My nephew flew out in a car accident for seven meters without a scratch.
It's because there's a big schoolbag on the back.
He said it was the first time he felt that reading was useful.
Knowledge Changes Destiny!
The final interpretation of the right to love Partner (www.23hhr.com) All, reproduced please indicate the source.
Struts2 struts2 File Upload detailed