文件上传:
1、JSP中提交method="post" enctype="multipart/form-data" 的表单
2、Action中接收file,fileFileName, fileContentType文件参数
3、 savedFile = new File("E:\\File", fileFileName); file.renameTo(savedFile);
文件下载:
1、点击下载 <s:a href="struts/downloadFile">下载</s:a>
2、获取文件路径 public InputStream getDownloadFile() throws Exception{this.fileName = "test.jpg" ;
return ServletActionContext.getServletContext().getResourceAsStream("upload/"+this.fileName) ;}
3、Action result 配置 <result name="success" type="stream">
<param name="contentType">text/plain</param>
<param name="contentDisposition">attachment;fileName="${fileName}"</param>
<param name="inputName">downloadFile</param>
<param name="bufferSize">1024</param>
</result>