日期:2014-05-18 浏览次数:20759 次
String filepath=request.getParameter("filepath");//获得文件路径
String filename=request.getParameter("filename");//获得文件名
String guessCharset="UTF-8";
try {
String isofilename = new String(filename.getBytes("ISO8859-1"),
guessCharset);
String isofilepath = new String(filepath.getBytes("ISO8859-1"),
guessCharset);
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition",
"attachment; filename=" + isofilename);
ServletOutputStream out = null;
out = response.getOutputStream();
ServletUtils.returnFile(isofilepath+File.separator+isofilename,out);//下载文件
}
catch (UnsupportedEncodingException ex) {//iso8559_1编码异常
ex.printStackTrace();
}catch(IOException e){//getOutputStream()异常。
e.printStackTrace();
}