📄 downloadfileaction.java
字号:
package com.iplan.portal.order.action;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.upload.FormFile;
import com.iplan.portal.framework.base.struts.BaseAction;
/**
* http://www.5ai7.net
*
* @author ws
*/
public class DownloadFileAction extends BaseAction {
public ActionForward download(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
FormFile formFile = (FormFile) daf.get("formFile");
String fileName = (String) daf.get("fileName");
fileName = "D:\\oceansoft\\Tomcat 5.0\\webapps\\iplan\\excle\\order.xls";
formFile.setFileName(fileName);
try {
OutputStream os = httpServletResponse.getOutputStream();
httpServletResponse.setContentType("application/x-msdownload");
httpServletResponse.setHeader("Content-Disposition", "attachment;"
+ " filename="
+ new String(fileName.getBytes(), "ISO-8859-1"));
os.write(formFile.getFileData());
os.close();
} catch (Exception e) {
}
return actionMapping.findForward("Excle");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -