读书人

使用cos下载的有关问题

发布时间: 2014-04-20 16:20:18 作者: rapoo

使用cos下载的问题
cos下载的时候出现一个问题,好只支持rar、xls等格式,txt、mht等格式都不支持。
使用cos下载的有关问题
下面贴出我的代码:
jsp页面我用的是超链接如<a>downFileServlet?filepath=filepath&filename=filename</a>
后台代码

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();
}

[解决办法]
参考一下http://blog.csdn.net/jadyer/article/details/6144901
[解决办法]
cos是什么,没玩过,余弦莫

读书人网 >J2EE开发

热点推荐