文件下载:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String inPutFileName = "附件2-2010年探亲路途费报销申请表.xls";
response.reset();
response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-Disposition", "attachment;filename=" + new String(inPutFileName.getBytes("gb2312"),"ISO8859-1"));
System.out.println("下载文件的路径:" + request.getRealPath(inPutFileName));
//System.out.println(CustgradeinputDownLoadAction.class.getClassLoader().getResource(""));
//打开指定文件的流信息
// InputStream is = new FileInputStream(request.getContextPath() + "/" +inPutFileName);
InputStream is = new FileInputStream(request.getRealPath(inPutFileName));
//写出流信息
int data = -1;
OutputStream outputstream = response.getOutputStream();
while ( (data = is.read()) != -1)
outputstream.write(data);
outputstream.flush();
outputstream.close();
is.close();
return null;
}