Struts Action 代码 package org.cxg.action; import java.io.InputStream; import java.io.UnsupportedEncodingException; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class DownLoadAction extends ActionSupport{ //下载文件原始存放路径 private final static String DOWNLOADFILEPATH="/"; //下载文件名 private String fileName ; public InputStream getInputStream() throws Exception{ return ServletActionContext.getServletContext().getResourceAsStream(DOWNLOADFILEPATH + fileName); } @Override public String execute() throws Exception { fileName = "小胖子.jpg"; return SUCCESS; } /** 提供转换编码后的供下载用的文件名 */ public String getDownloadFileName() { String downFileName = fileName; try { downFileName = new String(downFileName.getBytes(), "ISO8859-1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return downFileName; } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } } Struts.xml配置 <package name="default" namespace="/" extends="struts-default"> <action name="index" class="org.cxg.action.UploadAction" method="upload"> <result type="redirectAction"></result> </action> <action name="download" class="org.cxg.action.DownLoadAction" method="execute"> <result name="success" type="stream"> <param name="inputName">inputStream</param> <param name="contentType">image/jpeg;charset=ISO8859-1</param> <param name="contentDisposition">attachment;filename=${downloadFileName}</param> <param name="bufferSize">4096</param> </result> </action> </package>