struts2 在jsp一个上传框如何实现全选多个文件一次上传呢?
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";
}
}
<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属性
用multiple属性
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询