struts1.x 文件上传 formfile

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值