struts2 在jsp一个上传框如何实现全选多个文件一次上传呢?

 我来答
haogecs10000
推荐于2017-09-12 · 超过23用户采纳过TA的回答
知道答主
回答量:50
采纳率:0%
帮助的人:60.2万
展开全部
jsp代码
<s:form action="uploadAction!uploadFilemuch.action" method="post" enctype="multipart/form-data" >

File1:<s:file name="uploadmuch" label="selectfile"></s:file>
File2:<s:file name="uploadmuch" label="selectfile"></s:file>
File3:<s:file name="uploadmuch" label="selectfile"></s:file>
<s:submit value="submit" />

</s:form>
action代码
public class UpLoadFiled extends ActionSupport {

private File upload;
private String uploadFileName;

private File[] uploadmuch;
private String[] uploadmuchFileName;

public File getUpload() {
return upload;
}

public void setUpload(File upload) {
this.upload = upload;
}

public String getUploadFileName() {
return uploadFileName;
}

public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}

public File[] getUploadmuch() {
return uploadmuch;
}

public void setUploadmuch(File[] uploadmuch) {
this.uploadmuch = uploadmuch;
}

public String[] getUploadmuchFileName() {
return uploadmuchFileName;
}

public void setUploadmuchFileName(String[] uploadmuchFileName) {
this.uploadmuchFileName = uploadmuchFileName;
}

public String uploadFilemuch() throws IOException {
if (this.getUploadmuch() != null) {
for (int i = 0; i < this.getUploadmuch().length; i++) {
FileOutputStream fos = new FileOutputStream(
ServletActionContext.getRequest().getRealPath(
"\\upload")
+ "\\" + this.getUploadmuchFileName()[i]);
FileInputStream fis = new FileInputStream(this.getUploadmuch()[i]);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
}
}
ActionContext.getContext().put("message", "上传成功");
Log.addLog("上传成功");
return "message";
}

}
匿名用户
推荐于2017-10-11
展开全部
<input type="file" id="file" multiple size="80">
用multiple属性
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式