仅使用
<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(); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)