package com.cai.miniHr.struts.actions;
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;
public class ReportDownloadAction extends DownloadAction {
@Override
protected StreamInfo getStreamInfo(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// Set the file name
arg3.setHeader("Content-disposition", "attachment; filename=" + "a.jpg");
String contentType = "image/gif";
// String contentType = "application/vnd.ms-excel";
// File file = new File("D:\\a.xls");
File file = new File(this.servlet.getServletContext().getRealPath("/") + "images\\a.jpg");
// System.out.println(this.servlet.getServletContext().getRealPath("/") + "images\\a.jpg");
return new FileStreamInfo(contentType, file);
}
}
this.servlet.getServletContext().getRealPath("/") + "images\\a.jpg"即爲F:\me\tomcat6\apache-tomcat-6.0.20\webapps\miniHr\images\a.jpg