<script type="text/javascript">
input = document.createElement("input");button = document.createElement("input");
input.type = "file";
input.name = "file";
button.type = "button";
button.value = "remove";
button.onclick =
td.appendChild(br);
td.appendChild(input);
td.appendChild(button);
}
</script>
接收多个上传文件的动作类:
serialVersionUID = -5056971793538814980L;
setFileFileName(List<String> fileFileName)
{
this.fileFileName = fileFileName;
}
public List<String> getFileContentType()
{
return fileContentType;
}
public void setFileContentType(List<String> fileContentType)
{
this.fileContentType = fileContentType;
}
@Override
public String execute()
{
if (fileFile.size() == 0)
{
return INPUT;
}
else
{
for (int index = 0; index < fileFile.size(); index++)
{
String targetDir = "d:\images";
File savedFile = new File(targetDir, fileFileName.get(index));
fileFile.get(index).renameTo(savedFile);
}
}
return SUCCESS;
}
}
struts.xml配置信息:
/success_multi_upload.jsp
/multi_upload.jsp
100000
image/gif,image/jpeg,image/png
success_multi_upload.jsp:
Upload Successfully!
测试:
浏览器中输入::8081/Struts2/multi_upload.jsp,获得如下界面:
点击"Add More..."按钮,我们要上传10个文件:
可以看到现在页面动态的增加了上传文件的个数,我们还可以点击"remove"按钮动态减少上传文件的个数,下面选择上传文件:
点击"submit"按钮上传文件:
查看D盘下images文件夹:
可以看到我们选择的文件都上传成功了!