struts2
/WEB-INF/web.xml
blk struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* index.html
/WEB-INF/classes/struts.xml
/exceptionHandle/exception.jsp /exceptionHandle/exception.jsp \down\images\文件.zip application/zip targetFile filename="文件.zip" 4096
/down/strutsDown.html
Struts2的文件下载 Struts2的文件下载
下载Struts2的Logo:下载文件
down.FileDownloadAction
package down;import java.io.InputStream;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.Action;public class FileDownloadAction implements Action { private String inputPath; public void setInputPath(String value) { inputPath = value; } /* 下载用的Action应该返回一个InputStream实例, 该方法对应在result里的inputName属性值为targetFile */ public InputStream getTargetFile() throws Exception { return ServletActionContext.getServletContext().getResourceAsStream(inputPath); } public String execute() throws Exception { return SUCCESS; }}