我正在尝试上传多个文件,并将它们绑定到stripes框架中的一个java数组。我已经阅读了SO上的文档here和this question。然而,我仍然有一些问题。在debug中运行时,如果我上传多个文件,我注意到只有最后一个文件绑定到数组。我做错了什么?
<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
}发布于 2017-01-15 00:29:04
你可以省略二传手。已经通过new运算符初始化了attachments变量。
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]");
}按下表单上的“submit”调用“submit”Resolution,您现在可以检查填充的附件,保存它们,然后-在本例中-再次返回到表单。或者你可以向你的访问者展示另一个页面。
https://stackoverflow.com/questions/41640399
复制相似问题