81,114
社区成员
发帖
与我相关
我的任务
分享
java.io.BufferedInputStream bis=null;
java.io.BufferedOutputStream bos=null;
try{
DoradoContext context = DoradoContext.getContext();
ServletContext servletContext = ((HttpDoradoContext) context).getRequest().getSession().getServletContext();
String docRoot = servletContext.getRealPath("/");
String path = new String(request.getParameter("FilePath").getBytes("ISO-8859-1"), "GBK");
String filepath=docRoot+path;
String filename = new String(request.getParameter("ReportName").getBytes("ISO-8859-1"), "GBK");
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gb2312"),"iso8859-1"));
bis =new java.io.BufferedInputStream(new java.io.FileInputStream(filepath));
bos=new java.io.BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
}
}
catch(Exception e){
e.printStackTrace();
}
finally {
if (bis != null)bis.close();
if (bos != null)bos.close();
} java.io.InputStream bis = null;
java.io.OutputStream bos = null;
try {
DoradoContext context = DoradoContext.getContext();
ServletContext servletContext = ((HttpDoradoContext) context).getRequest().getSession().getServletContext();
String docRoot = servletContext.getRealPath("/");
String path = new String(request.getParameter("FilePath").getBytes("ISO-8859-1"), "GBK");
String filepath = docRoot + path;
String filename = new String(request.getParameter("ReportName").getBytes("ISO-8859-1"), "GBK");
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition", "attachment; filename="
+ new String(filename.getBytes("gb2312"), "iso8859-1"));
bis = new java.io.FileInputStream(filepath);
bos = response.getOutputStream();
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}