downfileaction.java
来自「实现一个J2EE上传功能完整的源代码」· Java 代码 · 共 31 行
JAVA
31 行
package com.action;import java.io.File;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DownloadAction;import org.apache.struts.actions.DownloadAction.FileStreamInfo;import org.apache.struts.actions.DownloadAction.StreamInfo;public class DownFileAction extends DownloadAction { protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String fileid = request.getParameter("fileid"); String filename = request.getParameter("filename"); String filetype = request.getParameter("filetype"); String endname = filename.substring(filename.indexOf(".")); String downname = fileid + endname; String dirpath = servlet.getServletContext().getRealPath("/file"); File file = new File(dirpath, downname); FileStreamInfo fsi = new FileStreamInfo(filetype, file); response.setHeader("Content-disposition", "attachment;filename=" + downname); return fsi; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?