If struts is used to realize dynamic (indefinite number) multi file upload?

A few days ago, I encountered a problem such as the problem description and asked for the effect like the attachment of e-mail 163. I found it on the Internet for a long time and didn't solve it. I tried intermittently for a few days to get it out. In order to help future friends who encounter similar problems successfully solve the problems, it is described here.

The main codes are as follows

Form part:

Public class multiuploadform extensions ActionForm {private list myfiles; public multiuploadform() {myfiles = new arraylist(); / / in order to display a file myfiles. Add (New uploadfile());} public List getMyFiles() { return myFiles; }

//Note the definition of this method

public UploadFile getUploadFile(int index){ int size = myFiles.size(); if(index>size-1){ myFiles.add(new UploadFile()); } return (UploadFile)myFiles. get(index); } public void setMyFiles(List myFiles) { this.myFiles = myFiles; } }

Dataset part: public class UploadFile implements serializable {private formfile file; public formfile getfile() {system.out.println ("run in UploadFile. Getfile()"); return file;} public void setFile(FormFile file) { this.file = file; } } Action part: public class multiuploadaction extensions action {public actionforward execute (actionmapping, ActionForm, HttpServletRequest request, httpservletresponse response) {multiuploadform multiuploadform = (multiuploadform) form; list myfiles = multiuploadform. Getmyfiles(); for (int i = 0; I < myfiles. Size(); I + +) { UploadFile uploadFile = (UploadFile)myFiles.get(i); FormFile file = uploadFile.getFile();

if(file==null){ System.out.println("file is null"); } else{

//If you can run here, you can upload using the method of single file upload. Loop system out. println("filename:::" + file.getFileName()); System. out. println("file size:::" + file.getFileSize()); } }

return null; } }

JSP part:

<%@ page contentType="text/html; charset=GBK" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>




var preHTML = innerHTML. substring(0,(targetIndex-6)); var subHTML = innerHTML. substring(targetIndex-6); num++; var insertHTML = ""; innerHTML = preHTML + insertHTML + subHTML;

multiUploadForm. innerHTML = innerHTML; // alert(multiUploadForm.innerHTML); } function upload(){ multiUploadForm.submit(); }

this is file



The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>