1、action中
private InputStream inputStream; // getter与setter public String download() throws Exception { // 指定要下载的文件 inputStream = new FileInputStream(filePath); // 指定默认的文件名(使用URL编码解决中文件乱码问题) String fileName = URLEncoder.encode(template.getName(), "utf-8"); ActionContext.getContext().put("fileName", fileName); return "download"; }
2、struts.xml
<result name="downloadProcessImage" type="stream"> <param name="inputName">inputStream</param> <!-- 指定下载文件的默认文件名 --> <param name="contentDisposition">attachment;filename="${#fileName}.doc"</param> </result>