有没有先设置字符集为中文?你的Cfilename 和生成的莫名其妙的文件名能 列出来看看吗?

解决方案 »

  1.   

    <%
    response.addHeader("content-type","application/msword");  
             response.addHeader("Content-Disposition", "attachment; filename=\"" + "temp.doc\"");//如果这里写死就没有问题
                response.setHeader("Connection",  "close");  
                response.setHeader("Content-Type",  "application/octet-stream");  
                   
       while  (rs.next())  
                   {  
                           InputStream  inFile  =  rs.getBinaryStream(1);  
                           int  length=0;  
                           int  STREAM_SIZE  =  1000000;  
                           byte[]  buffer  =  new  byte[STREAM_SIZE];  
                           while  ((length  =  inFile.read(buffer))  !=  -1)  
                           {  
                                   System.out.println("readed  lenth  =  "+length);  
                                   outFile.write(buffer,0,length)  ;  
       System.out.println("write over!!!!!!!!!!");
    }    
                   }  
                           rs.close();  
        System.out.println("111111111");
                           outFile.close(); 
        System.out.println("222222222222"); 
           }  catch(Exception  e)  
    {  
           e.printStackTrace();  
    }
    finally
    {  ConnectionMgr.close(sqlCon);
    System.out.println("3333333333333333333");
    }
    %>
    如果是写成一开始从库里取出来的文件名的话,我现在下载的文件名就像CAK5A3O5.这种奇怪的样子,为什么会这样?
      

  2.   

    我感觉问题就出在response.addHeader("Content-Disposition", "attachment; filename=\"" + Cfilename+"\"");
    调用这个方法以后,下载名好像是随机生成的一些数字符号,可能是 : leshui(大象无形)(有物混成,先天地生) 所说的编码问题,但是不知道该如何解决?
      

  3.   

    肯定是字符集不匹配!注意IE等浏览器默认的字符集是ISO8859-1有两个地方需要考虑:
       1. 你写response.addHeader("Content-Disposition", "attachment; filename=\"" + Cfilename+"\""); 的时候要确定Cfilename中的字符集是你要设置的字符集,如果不确定,把它转换为ISO8859-1或gbk;
       2. 在response.addHeader("content-type","application/msword");  里指定字符集(charset=gbk之类)试试?