public class UploadForm extends ActionForm{ private FormFile file0; private FormFile file1; public FormFile getFile0() { return file0; } public void setFile0(FormFile file0) { this.file0 = file0; } public FormFile getFile1() { return file1; } public void setFile1(FormFile file1) { this.file1 = file1; } }
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { List<FormFile> files = new ArrayList<FormFile>(); UploadForm acform = (UploadForm) form; Hashtable<?, ?> hash = acform.getMultipartRequestHandler().getAllElements(); for(Iterator<?> it=hash.keySet().iterator();it.hasNext();){ String key =it.next()+""; System.out.print(key+"/t"); System.out.println(((FormFile)hash.get(key)).getFileName()); if(key.matches("file//d")){ files.add((FormFile)hash.get(key)); } } System.out.println("xxxxxxxxxx"); System.out.println(acform.getFile0().getFileName()); System.out.println(acform.getFile1().getFileName()); return super.execute(mapping, form, request, response); }
<form-bean name="uploadForm" type="cn.upload.form.UploadForm"></form-bean>
<action path="/upload" name="uploadForm" type="cn.upload.action.UploadAction">
</action>
页面:
<form action="./upload.do" method="post" enctype="multipart/form-data">
<input type="file" name="file0">
<input type="file" name="file1">
<input type="submit" value="subit...">
</form>