action代碼:
contentType = "image/jpeg";
fileName = "裝傻.jpg";
contentDisposition = "attachment;filename=" + fileName;
ServletContext servletContext = ServletActionContext.getServletContext();
//ServletActionContext.getResponse().setCharacterEncoding("utf-8");
String realpath = servletContext.getRealPath(fileName);
inputStream = new FileInputStream(realpath);
contentLength = inputStream.available();
return SUCCESS;
xml:
<action name="fileDownload" class="com.struts2.filedownload.app.FileDownloadAction">
<result type="stream">
<param name="contentDisposition">${contentDisposition}</param>
<param name="contentType">${contentType}</param>
<param name="bufferSize">2048</param>
</result>
</action>

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/212941.html
標籤:Web 開發
