我正在尝试上传多个文件并将它们绑定到条带框架中的java数组。我已在SO上阅读了文档here和this question。但是,我仍然有问题。在调试中运行时,如果我上传多个文件,我注意到只有最后一个文件绑定到数组。我做错了什么?
<stripes:form>
<c:forEach varStatus="loop" begin="0" end="3">
<stripes:file name="attachments[${loop.index}]"/>
</c:forEach>
<stripes:submit name="submit" />
</stripes:form>
private List<FileBean> attachments = new ArrayList<FileBean>();
public void setAttachments(List<FileBean> attachments) throws IOException {
logger.info("*********************Attachments " + attachments.size());
this.attachments = attachments;
//documentation says to call FileBean.save or read them as a stream
}
答案 0 :(得分:1)
你可以省略设定者。 attachments
变量已通过new
运算符初始化。
private List<FileBean> attachments = new ArrayList<FileBean>();
public List<FileBean> getAttachments() {
return this.attachments;
}
public Resolution submit() {
System.out.println("********************* Attachments " + attachments.size());
return show();
}
@DefaultHandler
public Resolution show() {
return new ForwardResolution("[path to jsp]");
}
按&#39;提交&#39;在表单上调用&#39;提交&#39;解决方法,您现在可以检查已填充的附件,保存它们,以及 - 在此示例中 - 再次返回到表单。或者您可以向访问者显示另一页。