在struts1中上传文件

在struts1中上传文件,第1张

在struts1中上传文件

仅使用

<html:file property="upload" /
>不会使您的应用程序上传文件。

为了支持上传功能,您的表单必须具有enctype =“ multipart / form-data”

<html:form action="fileUploadAction" method="post" enctype="multipart/form-data">File : <html:file property="upload" /> <br/`><html:submit /></html:form`>

然后从表单bean中获取文件并按以下方式进行 *** 作

YourForm uploadForm = (YourForm) form;FileOutputStream outputStream = null;FormFile file = null;try {  file = uploadForm.getFile();  String path = getServlet().getServletContext().getRealPath("")+"/"+file.getFileName();  outputStream = new FileOutputStream(new File(path));  outputStream.write(file.getFileData());}finally {  if (outputStream != null) {    outputStream.close();  }}


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

原文地址: https://outofmemory.cn/zaji/5476217.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存