There are also two properties in action: Uploadfilename and Uploadcontenttype, which are used to encapsulate the file name and file type of the uploaded files, respectively. This is unique to the STRUTS2 design: the Strut2 action class directly encapsulates the file contents of the uploaded file via the file Type property, but this file property cannot get the file name and file type of the uploaded files. So Struts2 encapsulates the upload file name and file type information contained in the domain directly into the uploadfilename and Uploadcontenttype properties, which means that the Struts2 for the file field named XXX in the form, Use 3 properties in the corresponding action class to encapsulate the file field information: The XXX property of type file: Used to encapsulate the file content corresponding to the page file field. The Xxxfilename property of type string: The file name used to encapsulate the file corresponding to the file domain. The Xxxcontenttype property of type string: The file type used to encapsulate the file applied by the file domain. The following is the actual Java code: jsp page: <input type= "file" id= "upload" name= "upload"/> This name is the property corresponding to the action action class code: private File upload; private String uploadfilename; Private String uploadcontenttype; public void setupload (File upload) {& nbsp This.upload = upload; } public void Setuploadfilename (St Ring uploadfilename) { this.uploadfilename = uploadfilename; } public void SETUPLOADCOntenttype (String uploadcontenttype) { This.uploadcontenttype = uploadcontenttype; & nbsp } Set 3 properties. Give the set method separately. This way, you will be able to get the uploaded file, file name, file type. NOTE: this uploadfilename,uploadcontenttype. If the file property name is xxx (private file xxx;). Then this must be Xxxfilename, Xxxcontenttype. Then the set method can be given separately. Special note that the:,<s:file/> flag is not only tied to upload, but also Uploadcontenttype (the MIME type of the uploaded file) and Uploadfilename (the file name of the uploaded file, The file name does not include the path to the file). Therefore, the <s:file name= "xxx"/> Corresponds to the three properties of XXX, Xxxcontenttype, and xxxfilename inside the action class.
Struts file upload, get file name and file type