struts2批量上传文件提示以下异常

struts2批量上传文件提示以下异常,第1张

struts.multipart.saveDir没有配置。

struts.multipart.saveDir用于指定存放临时文件的文件夹,

是在,struts.xml配置文件中增加如下:

<constant

name="struts.multipart.saveDir"

value="/tmp"/>

设置临时文件上传路径。

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 = 0i <this.getUploadmuch().lengthi++) {

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"

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11918425.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存