查了不少文章,还是找不到原因,我的下载页面代码如下:
downloas.jsp:
<%
  java.io.BufferedInputStream bis=null;
  java.io.BufferedOutputStream  bos=null;
try{
 String filename=request.getParameter("filename");//接收文件名
 String path=request.getParameter("path");//接收传递路径
 filename=new String(filename.getBytes("iso8859-1"),"gb2312");
 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("e:\\ftp\\"+path+"\\"+filename));
 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();
}
%> 

解决方案 »

  1.   

    自己顶一下,查过一些帖子说是download.jsp页面非<%%>部分不允许有空格和回车,我去掉了,依旧还是下载后打开无法正常显示内容。哪位高手指点下啊,分数不够我可以再加啊。。谢谢哦
      

  2.   

    呃~怎么老在jsp页面里写代码。
    这两行代码什么意思?先把filename编码从iso8859-1转成gb2312
    然后又把filename编码从gb2312转成iso8859-1 !!!为什么要这么做?
    filename=new String(filename.getBytes("iso8859-1"),"gb2312");
    response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gb2312"),"iso8859-1"));
    再有一个你ftp的编码设的是什么?