使用自定义对象的列表(或映射),其中包含您的File,fileName和contentType(以及其他字段)。一个JSP 行 对应的元素,必须清楚。
我确实喜欢那样(因为我也有很多其他领域),而且它就像一种魅力。
(这 不是 唯一的方法,它只是当您还需要处理其他字段时将变得更加方便的一种工作方法)
POJO
public class MyCustomRow implements Serializable { private File fileUpload; private String fileUploadFileName; private String fileUploadContentType; private String otherField1; private String otherField2; }在行动
private List<MyCustomRow> rows;
在JSP中
<s:iterator value="rows" status="row"> <s:file name="rows[%{#row.index}].fileUpload" /> <s:textfield name="rows[%{#row.index}].otherField1"/> <s:textfield name="rows[%{#row.index}].otherField2"/></s:iterator>Struts2将自动检测并填充文件名和内容类型(确保堆栈中有FileUploadInterceptor)。



