if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0) filename = new String(filename.getBytes("GB2312"), "ISO8859-1");// firefox浏览器 else if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) filename = URLEncoder.encode(filename, "UTF-8");// IE浏览器 response.reset();// 如果有换行,对于文本文件没有什么问题,但是对于其它格 response.setContentType("application/x-msdownload;charset=GBK"); System.out.print(response.getContentType()); response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Disposition", "attachment; filename=" +new String(filename.getBytes("UTF-8"),"GBK"));//// response.setContentType("application/octet-stream");// response.setHeader("Content-Disposition", "attachment;filename=/""// + filename + "/"");//// response.setHeader("Connection", "close");
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = null; File d = new File("D:/"+feedback.getId()+"/"+fb.getRtName());// File d=new File(fb.getRtPath()); try{ if (d.exists()) { fis = new FileInputStream("D:/"+feedback.getId()+"/"+fb.getRtName());// fis = new FileInputStream(fb.getRtPath()); byte b[] = new byte[1000]; int j; while ((j = fis.read(b)) != -1) { try { sos.write(b, 0, j); } catch (IOException exp) {
} } } fis.close(); sos.flush(); sos.close(); }catch (Exception e) { String mailOK="下载失败"; request.getSession().setAttribute("mailOK", mailOK); }